-
Notifications
You must be signed in to change notification settings - Fork 6
/
ipctrain.cpp
59 lines (51 loc) · 1.22 KB
/
ipctrain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<bits/stdc++.h>
#define MAX 1000001
#define ll long long
#define DEBUG(x) do { std::cout << #x << ": " << x << " "; } while (0)
using namespace std;
struct trainer{
int d,t,s;
bool operator<(const trainer &a) const
{
return s < a.s;
}
};
int main()
{
//string str;
//char str[MAX];
int i,j,k,t,n;
bool days[MAX];
long long sum=0;
priority_queue <trainer> p;
cin>>t;
while(t--){
cin>>n>>k;
sum=0;
p = priority_queue <trainer>();
memset(days,0,sizeof(bool)*MAX);
for(i=0;i<n;++i){
trainer x;
cin>>x.d>>x.t>>x.s;
p.push(x);
}
while(!p.empty()){
trainer x= p.top();
p.pop();
int placed=0;
//DEBUG(x.d);DEBUG(x.t);DEBUG(x.s);
for(i=x.d;i<=k && x.t>0;++i){
if(days[i]==0){
days[i]=1;
x.t--;
//cout<<"placed at "<<i;
}
}
//DEBUG(placed);cout<<endl;
sum+= (x.t)*x.s;
//cout<<" "<<sum<<" ";
}
cout<<sum<<endl;
}
return 0;
}