-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathIPCTRAIN.cpp
59 lines (54 loc) · 926 Bytes
/
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
//Code by ista2000 / Istasis Mishra
#include <bits/stdc++.h>
using namespace std;
#define int long long int
struct tr
{
int d, t, s;
};
bool cmp(tr tr1, tr tr2)
{
return tr1.d < tr2.d;
}
const int mod = 1e9 + 7;
#undef int
int main()
{
#define int long long int
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc;
cin>>tc;
while(tc--)
{
int n, m;
cin >> n >> m;
vector<tr> v(n);
for(int i = 0;i<n;i++)
cin >> v[i].d >> v[i].t >> v[i].s;
sort(v.begin(), v.end(), cmp);
priority_queue< pair<int,int> > pq;
int cnt = 0;
for(int i = 0;i <= m;i++)
{
for(;cnt<n;)
{
if(v[cnt].d > i)
break;
pq.push(make_pair(v[cnt].s, cnt));
cnt++;
}
if(pq.empty()) continue;
auto pp = pq.top();
v[pp.second].t--;
if(v[pp.second].t == 0)
pq.pop();
}
int anss = 0;
for(int i = 0;i<n;i++)
anss += v[i].t * v[i].s;
cout << anss << endl;
}
return 0;
}