#include <bits/stdc++.h>
using namespace std;
struct camp{
long long x, g, e;
};
signed main() {
long long n, maxx = 0, sumx = 0, sumg= 0, sume = 0, left = 0, right = 0;
cin >> n;
vector<camp> vec(n);
for (int i = 0; i< n; i++) {
cin >> vec[i].x >> vec[i].g >> vec[i].e;
}
while (left <=right){
sumx = vec[right].x-vec[left].x;
sume +=vec[right].e;
if(sume>=sumx && right<n-1){
sumg += vec[right].g;
maxx = max(sumg,maxx);
right++;
}else{
maxx = max(sumg,maxx);
sumg-=vec[left].g;
sume-=vec[left].e;
if (left>right){
right = left;
}
left++;
}
sume = abs(sume);
sumg = abs(sumg);
sumx = abs(sumx);
}
maxx = max(sumg,maxx);
cout << maxx;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |