#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
int x[MAX_N], g[MAX_N], d[MAX_N];
int tree[4 * MAX_N];
void build(int idx, int l, int r) {
if(l == r) {
return void(tree[idx] = l);
}
int mid = (l + r) / 2;
build(idx * 2, l, mid);
build(idx * 2 + 1, mid + 1, r);
int L = tree[idx * 2], R = tree[idx * 2 + 1];
if(x[L] - d[L - 1] >= x[R] - x[R - 1]) {
tree[idx] = tree[idx * 2];
}
else {
tree[idx] = tree[idx * 2 + 1];
}
}
int query(int idx, int l, int r, int ql, int qr) {
if(r < ql or qr < l) {
return -1;
}
if(ql <= l and r <= qr) {
return tree[idx];
}
int mid = (l + r) / 2;
int L = query(idx * 2, l, mid, ql, qr);
int R = query(idx * 2 + 1, mid + 1, r, ql, qr);
if(L == -1) {
return R;
}
if(R == -1) {
return L;
}
if(x[L] - d[L - 1] >= x[R] - d[R - 1]) {
return L;
}
return R;
}
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];
}
build(1, 1, N);
int ans = 0;
for(int i = 1; i <= N; i++) {
int l = 1, r = i, pos;
while(l <= r) {
int mid = (l + r) / 2;
int j = query(1, 1, N, 1, mid);
if(x[i] - x[j] <= d[i] - d[j - 1]) {
r = mid - 1;
pos = mid;
}
else {
l = mid + 1;
}
}
ans = max(ans, g[i] - g[pos - 1]);
}
cout << ans;
return 0;
}
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:77:37: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
77 | ans = max(ans, g[i] - g[pos - 1]);
| ~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |