#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 100000
int x[MAXN], g[MAXN], d[MAXN], n;
int prg[MAXN], prd[MAXN];
bool can (int LEN) {
for (int left = 0; left < n; left ++) {
int right = lower_bound(x, x + n, x[left] + LEN) - x;
if (right >= 0 && right < n)
if (prd[right] - (left == 0 ? 0 : prd[left - 1]) >= x[right] - x[left]) {
return true;
}
}
return false;
}
signed main() {
//ios::sync_with_stdio(0);
//cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> g[i] >> d[i];
}
for (int i = 0; i < n; i++) {
prg[i] = g[i];
prd[i] = d[i];
if (i)
prg[i] += prg[i - 1],
prd[i] += prd[i - 1];
}
int l = 0, r = 1e9;
while (l < r) {
int LEN = (l + r + 1) / 2;
if (can (LEN)) {
l = LEN;
} else {
r = LEN - 1;
}
//cout << l << ' ' << r << '\n';
}
int ans = 0, LEN = l, cnt = 0;
for (int left = 0; left < n; left ++) {
int right = lower_bound(x, x + n, x[left] + LEN) - x;
//cout << left << ' ' << right << '\n';
if (right >= 0 && right < n)
if (prd[right] - (left == 0 ? 0 : prd[left - 1]) >= x[right] - x[left]) {
cnt++;
ans = max(ans, prg[right] - (left == 0 ? 0 : prg[left - 1]));
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |