#include <bits/extc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#define int long long
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) do{auto y = x; cout << #x << " = " << y << endl;}while(0)
// #define endl "\n"
#define unordered_map __gnu_pbds::gp_hash_table
using pii = pair<int, int>;
const int inf = 1ll << 60;
const int MOD = 1e9 + 7;
struct fuel {
int x, a, b;
};
bool operator<(fuel a, fuel b) {
return a.x < b.x;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, d; cin >> n >> d;
vector<fuel> fs(n);
for(int i = 0; i < n; i++) {
cin >> fs[i].x >> fs[i].a >> fs[i].b;
}
fs.push_back({d, 0, 0});
sort(all(fs));
auto bcmp = [](fuel a, fuel b) {
return a.b > b.b;
};
priority_queue<fuel, vector<fuel>, decltype(bcmp)> pq(bcmp);
int sf = 0, cf = 0, pos = 0;
for(auto f : fs) {
cf -= f.x - pos;
pos = f.x;
if(cf < 0) {
sf -= cf;
cf = 0;
while(pq.size() && pq.top().b < sf) {
sf += pq.top().a;
pq.pop();
}
}
if(sf < f.b) {
cf += f.a;
pq.push(f);
}
}
cout << sf << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
27212 KB |
Output is correct |
2 |
Correct |
146 ms |
27092 KB |
Output is correct |
3 |
Correct |
138 ms |
27084 KB |
Output is correct |
4 |
Correct |
136 ms |
27088 KB |
Output is correct |
5 |
Correct |
148 ms |
27088 KB |
Output is correct |
6 |
Correct |
145 ms |
27080 KB |
Output is correct |
7 |
Correct |
152 ms |
27204 KB |
Output is correct |
8 |
Correct |
131 ms |
27068 KB |
Output is correct |
9 |
Correct |
150 ms |
27092 KB |
Output is correct |
10 |
Correct |
138 ms |
27080 KB |
Output is correct |
11 |
Correct |
152 ms |
27084 KB |
Output is correct |
12 |
Correct |
129 ms |
27000 KB |
Output is correct |
13 |
Correct |
154 ms |
27088 KB |
Output is correct |
14 |
Correct |
141 ms |
27112 KB |
Output is correct |
15 |
Correct |
153 ms |
27084 KB |
Output is correct |
16 |
Correct |
196 ms |
27084 KB |
Output is correct |
17 |
Correct |
174 ms |
27028 KB |
Output is correct |
18 |
Correct |
172 ms |
27080 KB |
Output is correct |
19 |
Correct |
156 ms |
27044 KB |
Output is correct |
20 |
Correct |
162 ms |
27088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1256 KB |
Output is correct |
3 |
Correct |
5 ms |
1256 KB |
Output is correct |
4 |
Correct |
6 ms |
1256 KB |
Output is correct |
5 |
Correct |
6 ms |
1256 KB |
Output is correct |
6 |
Correct |
5 ms |
1256 KB |
Output is correct |
7 |
Correct |
5 ms |
1256 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1256 KB |
Output is correct |
3 |
Correct |
5 ms |
1256 KB |
Output is correct |
4 |
Correct |
6 ms |
1256 KB |
Output is correct |
5 |
Correct |
6 ms |
1256 KB |
Output is correct |
6 |
Correct |
5 ms |
1256 KB |
Output is correct |
7 |
Correct |
5 ms |
1256 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
320 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
216 KB |
Output is correct |
28 |
Correct |
1 ms |
216 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
5 ms |
1256 KB |
Output is correct |
18 |
Correct |
5 ms |
1256 KB |
Output is correct |
19 |
Correct |
6 ms |
1256 KB |
Output is correct |
20 |
Correct |
6 ms |
1256 KB |
Output is correct |
21 |
Correct |
5 ms |
1256 KB |
Output is correct |
22 |
Correct |
5 ms |
1256 KB |
Output is correct |
23 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
144 ms |
27212 KB |
Output is correct |
17 |
Correct |
146 ms |
27092 KB |
Output is correct |
18 |
Correct |
138 ms |
27084 KB |
Output is correct |
19 |
Correct |
136 ms |
27088 KB |
Output is correct |
20 |
Correct |
148 ms |
27088 KB |
Output is correct |
21 |
Correct |
145 ms |
27080 KB |
Output is correct |
22 |
Correct |
152 ms |
27204 KB |
Output is correct |
23 |
Correct |
131 ms |
27068 KB |
Output is correct |
24 |
Correct |
150 ms |
27092 KB |
Output is correct |
25 |
Correct |
138 ms |
27080 KB |
Output is correct |
26 |
Correct |
152 ms |
27084 KB |
Output is correct |
27 |
Correct |
129 ms |
27000 KB |
Output is correct |
28 |
Correct |
154 ms |
27088 KB |
Output is correct |
29 |
Correct |
141 ms |
27112 KB |
Output is correct |
30 |
Correct |
153 ms |
27084 KB |
Output is correct |
31 |
Correct |
196 ms |
27084 KB |
Output is correct |
32 |
Correct |
174 ms |
27028 KB |
Output is correct |
33 |
Correct |
172 ms |
27080 KB |
Output is correct |
34 |
Correct |
156 ms |
27044 KB |
Output is correct |
35 |
Correct |
162 ms |
27088 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
5 ms |
1256 KB |
Output is correct |
38 |
Correct |
5 ms |
1256 KB |
Output is correct |
39 |
Correct |
6 ms |
1256 KB |
Output is correct |
40 |
Correct |
6 ms |
1256 KB |
Output is correct |
41 |
Correct |
5 ms |
1256 KB |
Output is correct |
42 |
Correct |
5 ms |
1256 KB |
Output is correct |
43 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |