#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int x[N], g[N], d[N];
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> x[i] >> g[i] >> d[i];
}
int l = 0;
long long curenergy = 0, curgold = 0, ans = 0;
for(int i = 1; i <= n; i++){
ans = max(ans, (long long)g[i]);
if(curenergy + d[i] >= x[i] - x[l]){
curenergy += d[i];
curgold += g[i];
}else{
while(curenergy + d[i] < x[i] - x[l]){
curenergy -= d[l];
curgold -= g[l];
l++;
}
curenergy += d[i];
curgold += g[i];
}
ans = max(ans, curgold);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 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 |
376 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 |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
436 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 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 |
1944 KB |
Output is correct |
5 |
Correct |
107 ms |
2236 KB |
Output is correct |
6 |
Correct |
227 ms |
4336 KB |
Output is correct |
7 |
Correct |
153 ms |
3172 KB |
Output is correct |
8 |
Correct |
157 ms |
3336 KB |
Output is correct |
9 |
Correct |
158 ms |
3060 KB |
Output is correct |
10 |
Incorrect |
146 ms |
3192 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |