#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int x[N], g[N], d[N];
bool vis[N];
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> x[i] >> g[i] >> d[i];
}
long long curenergy = 0, curgold = 0, ans = 0;
int r = 0;
for(int i = 1; i <= n; i++){
if(i > r){
curenergy += d[i];
curgold += g[i];
r = i;
}
while(curenergy < x[r] - x[i]){
curenergy -= d[r];
curgold -= g[r];
r--;
}
while(r + 1 <= n && curenergy + d[r + 1] >= x[r + 1] - x[i]){
curenergy += d[r + 1];
curgold += g[r + 1];
r++;
}
ans = max(ans, curgold);
curenergy -= d[i];
curgold -= g[i];
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
360 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
504 KB |
Output is correct |
2 |
Correct |
14 ms |
632 KB |
Output is correct |
3 |
Correct |
17 ms |
632 KB |
Output is correct |
4 |
Correct |
85 ms |
1912 KB |
Output is correct |
5 |
Correct |
102 ms |
2296 KB |
Output is correct |
6 |
Correct |
221 ms |
4496 KB |
Output is correct |
7 |
Correct |
151 ms |
3284 KB |
Output is correct |
8 |
Correct |
157 ms |
3296 KB |
Output is correct |
9 |
Correct |
145 ms |
3228 KB |
Output is correct |
10 |
Incorrect |
148 ms |
3064 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |