#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
long long x[MAX_N], g[MAX_N], d[MAX_N];
vector <pair <long long, long long>> vec;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
for(int i = 1; i <= N; i++) {
cin >> x[i] >> g[i] >> d[i];
g[i] += g[i - 1];
d[i] += d[i - 1];
}
long long ans = g[1];
vec.emplace_back(x[1], 0);
for(int i = 2; i <= N; i++) {
if(x[i] - d[i - 1] < vec.back().first) {
vec.emplace_back(x[i] - d[i - 1], g[i - 1]);
}
int l = 0, r = vec.size() - 1;
while(l < r) {
int mid = (l + r) / 2;
if(x[i] - d[i] <= vec[mid].first) {
r = mid;
}
else {
l = mid + 1;
}
}
ans = max(ans, g[i] - g[i - 1]);
if(x[i] - d[i] <= vec[l].first) {
ans = max(ans, g[i] - vec[l].second);
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |