#include <bits/stdc++.h>
#define ii pair <int, int>
#define F first
#define S second
using namespace std;
const int mod = 1e9 + 7;
const int N = 3e5 + 5;
int n, d, a[N], b[N], x[N];
int sr[N], t[N];
int Max[4 * N], lazy[4 * N];
void build(int s, int l, int r){
if (l == r){
Max[s] = sr[l];
return;
}
int mid = l + r >> 1;
build(2 * s, l, mid);
build(2 * s + 1, mid + 1, r);
Max[s] = max(Max[2 * s], Max[2 * s + 1]);
}
void update(int s, int l, int r, int u, int val){
if (u <= l){
lazy[s] += val;
Max[s] += val;
return;
}
int mid = l + r >> 1;
if (mid >= u) update(2 * s, l, mid, u, val);
update(2 * s + 1, mid + 1, r, u, val);
Max[s] = max(Max[2 * s], Max[2 * s + 1]) + lazy[s];
}
void solve(){
cin >> n >> d;
for (int i = 1; i <= n; ++ i) {
cin >> x[i] >> a[i] >> b[i];
sr[i] = x[i];
t[i] = i;
}
++ n;
x[n] = d;
sr[n] = d;
a[n] = 0;
sort(sr + 1, sr + n + 1);
for (int i = 1; i <= n; ++ i) x[i] = lower_bound(sr + 1, sr + n + 1, x[i]) - sr;
sort(t + 1, t + n + 1, [&](int u, int v){
return b[u] > b[v];
});
int ans = d;
build(1, 1, n);
for (int z = 1; z <= n; ++ z){
//cout << Max[1] << endl;
int i = t[z];
update(1, 1, n, x[i] + 1, -a[i]);
if (Max[1] <= b[i]) ans = Max[1];
}
cout << max(0, ans);
}
int main(){
//freopen("code.inp", "r", stdin);
//freopen("code.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t --) solve();
return 0;
}
Compilation message
FuelStation.cpp: In function 'void build(int, int, int)':
FuelStation.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
21 | int mid = l + r >> 1;
| ~~^~~
FuelStation.cpp: In function 'void update(int, int, int, int, int)':
FuelStation.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
172 ms |
15700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
7 ms |
8540 KB |
Output is correct |
3 |
Correct |
6 ms |
8792 KB |
Output is correct |
4 |
Correct |
6 ms |
8540 KB |
Output is correct |
5 |
Correct |
6 ms |
8796 KB |
Output is correct |
6 |
Correct |
7 ms |
8796 KB |
Output is correct |
7 |
Correct |
6 ms |
8796 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
6 ms |
8796 KB |
Output is correct |
15 |
Correct |
6 ms |
8796 KB |
Output is correct |
16 |
Correct |
6 ms |
8796 KB |
Output is correct |
17 |
Correct |
6 ms |
8796 KB |
Output is correct |
18 |
Correct |
6 ms |
8796 KB |
Output is correct |
19 |
Correct |
5 ms |
8772 KB |
Output is correct |
20 |
Correct |
5 ms |
8792 KB |
Output is correct |
21 |
Correct |
5 ms |
8796 KB |
Output is correct |
22 |
Correct |
5 ms |
8540 KB |
Output is correct |
23 |
Correct |
5 ms |
8540 KB |
Output is correct |
24 |
Correct |
5 ms |
8776 KB |
Output is correct |
25 |
Correct |
5 ms |
8796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
7 ms |
8540 KB |
Output is correct |
3 |
Correct |
6 ms |
8792 KB |
Output is correct |
4 |
Correct |
6 ms |
8540 KB |
Output is correct |
5 |
Correct |
6 ms |
8796 KB |
Output is correct |
6 |
Correct |
7 ms |
8796 KB |
Output is correct |
7 |
Correct |
6 ms |
8796 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
6 ms |
8796 KB |
Output is correct |
15 |
Correct |
6 ms |
8796 KB |
Output is correct |
16 |
Correct |
6 ms |
8796 KB |
Output is correct |
17 |
Correct |
6 ms |
8796 KB |
Output is correct |
18 |
Correct |
6 ms |
8796 KB |
Output is correct |
19 |
Correct |
5 ms |
8772 KB |
Output is correct |
20 |
Correct |
5 ms |
8792 KB |
Output is correct |
21 |
Correct |
5 ms |
8796 KB |
Output is correct |
22 |
Correct |
5 ms |
8540 KB |
Output is correct |
23 |
Correct |
5 ms |
8540 KB |
Output is correct |
24 |
Correct |
5 ms |
8776 KB |
Output is correct |
25 |
Correct |
5 ms |
8796 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
171 ms |
15680 KB |
Output is correct |
28 |
Correct |
195 ms |
15700 KB |
Output is correct |
29 |
Correct |
167 ms |
15564 KB |
Output is correct |
30 |
Correct |
202 ms |
15508 KB |
Output is correct |
31 |
Correct |
176 ms |
15696 KB |
Output is correct |
32 |
Correct |
170 ms |
15448 KB |
Output is correct |
33 |
Correct |
1 ms |
8536 KB |
Output is correct |
34 |
Correct |
1 ms |
8540 KB |
Output is correct |
35 |
Correct |
1 ms |
8540 KB |
Output is correct |
36 |
Correct |
1 ms |
8540 KB |
Output is correct |
37 |
Correct |
1 ms |
8540 KB |
Output is correct |
38 |
Correct |
1 ms |
8540 KB |
Output is correct |
39 |
Correct |
166 ms |
15696 KB |
Output is correct |
40 |
Correct |
182 ms |
15556 KB |
Output is correct |
41 |
Correct |
171 ms |
15512 KB |
Output is correct |
42 |
Correct |
166 ms |
15696 KB |
Output is correct |
43 |
Correct |
193 ms |
15696 KB |
Output is correct |
44 |
Correct |
163 ms |
15572 KB |
Output is correct |
45 |
Correct |
151 ms |
15700 KB |
Output is correct |
46 |
Correct |
163 ms |
15696 KB |
Output is correct |
47 |
Correct |
150 ms |
15696 KB |
Output is correct |
48 |
Correct |
149 ms |
15508 KB |
Output is correct |
49 |
Correct |
171 ms |
15764 KB |
Output is correct |
50 |
Correct |
175 ms |
15696 KB |
Output is correct |
51 |
Correct |
171 ms |
15572 KB |
Output is correct |
52 |
Correct |
177 ms |
15696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
8536 KB |
Output is correct |
17 |
Correct |
1 ms |
8536 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
1 ms |
8540 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
1 ms |
8536 KB |
Output is correct |
30 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
7 ms |
8540 KB |
Output is correct |
18 |
Correct |
6 ms |
8792 KB |
Output is correct |
19 |
Correct |
6 ms |
8540 KB |
Output is correct |
20 |
Correct |
6 ms |
8796 KB |
Output is correct |
21 |
Correct |
7 ms |
8796 KB |
Output is correct |
22 |
Correct |
6 ms |
8796 KB |
Output is correct |
23 |
Correct |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
1 ms |
8540 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
6 ms |
8796 KB |
Output is correct |
30 |
Correct |
6 ms |
8796 KB |
Output is correct |
31 |
Correct |
6 ms |
8796 KB |
Output is correct |
32 |
Correct |
6 ms |
8796 KB |
Output is correct |
33 |
Correct |
6 ms |
8796 KB |
Output is correct |
34 |
Correct |
5 ms |
8772 KB |
Output is correct |
35 |
Correct |
5 ms |
8792 KB |
Output is correct |
36 |
Correct |
5 ms |
8796 KB |
Output is correct |
37 |
Correct |
5 ms |
8540 KB |
Output is correct |
38 |
Correct |
5 ms |
8540 KB |
Output is correct |
39 |
Correct |
5 ms |
8776 KB |
Output is correct |
40 |
Correct |
5 ms |
8796 KB |
Output is correct |
41 |
Correct |
1 ms |
8540 KB |
Output is correct |
42 |
Correct |
6 ms |
8540 KB |
Output is correct |
43 |
Correct |
6 ms |
8796 KB |
Output is correct |
44 |
Incorrect |
6 ms |
8796 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Incorrect |
172 ms |
15700 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |