-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPCTRAIN.cpp
80 lines (74 loc) · 2.09 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// https://www.codechef.com/JULY17/problems/IPCTRAIN
#include <iostream>
#include <queue>
#include <vector>
class Trainer {
public:
int d;
int t;
int s;
Trainer(int d, int t, int s) {
this->d = d;
this->t = t;
this->s = s;
}
void decrement();
};
void Trainer::decrement() {
this->t--;
}
class CompareDate {
public: bool operator() (Trainer t1, Trainer t2) {
return t1.d > t2.d;
}
};
class CompareSadness {
public: bool operator() (Trainer t1, Trainer t2) {
return t1.s < t2.s;
}
};
int main(void) {
int T;
int d,t,s;
std::cin >> T;
while (T--) {
int N,D;
std::priority_queue<Trainer, std::vector<Trainer>, CompareDate> pqd;
std::priority_queue<Trainer, std::vector<Trainer>, CompareSadness> pqs;
std::cin >> N;
std::cin >> D;
for (int i=0; i < N; i++) {
std::cin >> d;
std::cin >> t;
std::cin >> s;
pqd.push(Trainer(d,t,s));
}
for (int d = 1; d <= D; d++) {
// std::cout << "d_iter: " << d << "\n";
while (!pqd.empty() && pqd.top().d == d) {
// std::cout << pqd.empty() << "\n";
Trainer temp = pqd.top();
// std::cout << "d: " << temp.d << " t:"<< temp.t << " s:" << temp.s << "\n";
pqs.push(temp);
pqd.pop();
}
if (!pqs.empty()) {
Trainer temp = pqs.top();
// std::cout << "Popped from pqs, d: " << temp.d << " t:"<< temp.t << " s:" << temp.s << "\n";
pqs.pop();
if (temp.t > 1) {
temp.decrement();
pqs.push(temp);
}
}
}
long long int total_sadness = 0;
// Remaining stuff
while (!pqs.empty()) {
Trainer temp = pqs.top();
pqs.pop();
total_sadness += (long long int) temp.t * temp.s;
}
std::cout << total_sadness << "\n";
}
}