-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIPC_Trainers.cpp
64 lines (53 loc) · 1.46 KB
/
IPC_Trainers.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
60
61
62
63
64
#include<bits/stdc++.h>
using namespace std;
// A structure is needed for each teacher to improve our input characteristics
struct Trainer
{
long long int date,time,sadness;
};
// A bool comparator is needed to arange the days of the trainers in increasing order
bool comparator(struct Trainer a,struct Trainer b)
{
return a.date < b.date;
}
int main()
{
int T;
cin >> T;
while(T--)
{
struct Trainer arr[100001]={0,0,0}; //Stores the max value of date,trainers,sadness
long long int N,D;
priority_queue <pair<long long int, long long int>> sad_checker; //Will prioiritize the max sadness for us
pair<long long int,long long int> var; //Keeps a track of the trainer to be added for the final answer
cin >> N >> D;
for(int i=0;i<N;i++){
cin >> arr[i].date >> arr[i].time >> arr[i].sadness;
}
long long int j=0; // Keeps a track of every person
sort(arr,arr+N,comparator); // We get a sorted list of trainers according to their joining dates
for(int i=1;i<=D;i++)
{
while(j<N && arr[j].date==i)
{
sad_checker.push(make_pair(arr[j].sadness,arr[j].time));
j++;
}
if(!sad_checker.empty())
{
var = sad_checker.top();
sad_checker.pop();
var.second--; // Tine decreases by one
if(var.second!=0)sad_checker.push(var);
}
}
long long int sol = 0; //The final answer
while(!sad_checker.empty())
{
var = sad_checker.top();
sad_checker.pop();
sol += (var.first)*(var.second);
}
cout << sol << endl;
}
}