forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path148.cpp
More file actions
64 lines (60 loc) · 1.08 KB
/
148.cpp
File metadata and controls
64 lines (60 loc) · 1.08 KB
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
//ac
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
class station {
public:
int cost;
int idx;
int dif;
bool operator < (const station& r) const {
return dif < r.dif;
}
};
int n;
int main() {
scanf("%d", &n);
vector<station> mm(n + 1);
vector<int> sum(n + 1);
sum[0] = 0;
for (int i = 1; i <= n; ++i) {
int now, total;
scanf("%d %d %d", &now, &total, &mm[i].cost);
mm[i].idx = i;
sum[i] = sum[i - 1] + now;
mm[i].dif = sum[i] - total;
}
priority_queue<station> que, bk;
int ret = 1000000000;
int cost = 0;
for (int i = n; i >= 1; --i) {
cost += mm[i].cost;
while (!que.empty()) {
station tmp = que.top();
if (tmp.dif > sum[i - 1]) {
cost -= tmp.cost;
que.pop();
}
else break;
}
que.push(mm[i]);
if (cost < ret) {
ret = cost;
bk = que;
}
}
vector<int> out;
while (!bk.empty()) {
out.push_back(bk.top().idx);
bk.pop();
}
sort(out.begin(), out.end());
for (int i = 0; i < out.size(); ++i) {
printf("%d\n", out[i]);
}
return 0;
}