-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChefJuly1.cpp
More file actions
51 lines (51 loc) · 931 Bytes
/
ChefJuly1.cpp
File metadata and controls
51 lines (51 loc) · 931 Bytes
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
#include<bits/stdc++.h>
#define test int t;scanf("%d",&t);while(t--)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
using namespace std;
void display(priority_queue<pii > que)
{
while(!que.empty())
{
printf("%d %d, ",que.top().first,que.top().second);
que.pop();
}
printf("\n");
}
int main()
{
test
{
int n,d,n1,d1,s1;
long long int total=0;
scanf("%d%d",&n,&d);
vector<pii > teacher[d+1];
loop(i,0,n)
{
scanf("%d%d%d",&d1,&n1,&s1);
teacher[d1].push_back(make_pair(s1,n1));
}
priority_queue<pii > que;
loop(i,1,d+1)
{
loop(j,0,teacher[i].size())
que.push(teacher[i][j]);
if(que.empty())
continue;
s1=que.top().first;
n1=que.top().second;
que.pop();
n1-=1;
if(n1)
que.push(make_pair(s1,n1));
}
// display(que);
while(!que.empty())
{
total+=que.top().first*que.top().second;
que.pop();
}
printf("%lld\n",total);
}
return 0;
}