#include <bits/stdc++.h>
#define INF 987654321
using namespace std;
typedef long long ll;
struct Mine {
int x, g, d;
}A[100005];
struct seg_tree {
int tree[444444], base;
void init(int x) { for(base = 1; base < x; base <<= 1); for(int i=1; i<base*2; i++) tree[i] = INF; }
void update(int x, int y) {
x += base - 1;
if(tree[x] < y) return;
tree[x] = y;
x >>= 1;
while(x) {
tree[x] = min(tree[x*2], tree[x*2+1]);
x >>= 1;
}
}
int RMQ(int s, int e) {
s += base - 1, e += base - 1;
int res = INF;
while(s < e) {
if(s & 1) res = min(res, tree[s++]);
if(!(e & 1)) res = min(res, tree[e--]);
s >>= 1, e >>= 1;
}
if(s == e) res = min(res, tree[s]);
return res;
}
}S;
int N;
ll ans, Gsum[100005], Dsum[100005];
ll idx[100005];
int find_idx(ll x) { return lower_bound(idx + 1, idx + N + 1, x) - idx; }
int main() {
scanf("%d", &N);
S.init(N);
for(int i=1; i<=N; i++) scanf("%d %d %d", &A[i].x, &A[i].g, &A[i].d);
for(int i=1; i<=N; i++) {
Gsum[i] += Gsum[i-1] + (ll)A[i].g;
Dsum[i] += Dsum[i-1] + (ll)A[i].d;
}
for(int i=1; i<=N; i++) idx[i] = (ll)A[i].x - Dsum[i-1];
sort(idx + 1, idx + N + 1);
ans = A[1].g;
for(int i=1; i<=N; i++) {
S.update(find_idx(A[i].x - Dsum[i-1]), i - 1);
int midx = find_idx(A[i].x - Dsum[i]);
midx = S.RMQ(midx, N);
ans = max(ans, Gsum[i] - Gsum[min(i - 1, midx)]);
}
printf("%lld\n", ans);
}
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:43:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
^
divide.cpp:45:73: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1; i<=N; i++) scanf("%d %d %d", &A[i].x, &A[i].g, &A[i].d);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
7272 KB |
Output is correct |
2 |
Correct |
0 ms |
7272 KB |
Output is correct |
3 |
Correct |
0 ms |
7272 KB |
Output is correct |
4 |
Correct |
0 ms |
7272 KB |
Output is correct |
5 |
Correct |
0 ms |
7272 KB |
Output is correct |
6 |
Correct |
0 ms |
7272 KB |
Output is correct |
7 |
Correct |
0 ms |
7272 KB |
Output is correct |
8 |
Correct |
0 ms |
7272 KB |
Output is correct |
9 |
Correct |
0 ms |
7272 KB |
Output is correct |
10 |
Correct |
0 ms |
7272 KB |
Output is correct |
11 |
Correct |
0 ms |
7272 KB |
Output is correct |
12 |
Correct |
0 ms |
7272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
7272 KB |
Output is correct |
2 |
Correct |
0 ms |
7272 KB |
Output is correct |
3 |
Correct |
0 ms |
7272 KB |
Output is correct |
4 |
Correct |
0 ms |
7272 KB |
Output is correct |
5 |
Correct |
0 ms |
7272 KB |
Output is correct |
6 |
Correct |
0 ms |
7272 KB |
Output is correct |
7 |
Correct |
0 ms |
7272 KB |
Output is correct |
8 |
Correct |
0 ms |
7272 KB |
Output is correct |
9 |
Correct |
0 ms |
7272 KB |
Output is correct |
10 |
Correct |
0 ms |
7272 KB |
Output is correct |
11 |
Correct |
3 ms |
7272 KB |
Output is correct |
12 |
Correct |
3 ms |
7272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
7272 KB |
Output is correct |
2 |
Correct |
0 ms |
7272 KB |
Output is correct |
3 |
Correct |
6 ms |
7272 KB |
Output is correct |
4 |
Correct |
29 ms |
7272 KB |
Output is correct |
5 |
Correct |
36 ms |
7272 KB |
Output is correct |
6 |
Correct |
73 ms |
7272 KB |
Output is correct |
7 |
Correct |
53 ms |
7272 KB |
Output is correct |
8 |
Correct |
56 ms |
7272 KB |
Output is correct |
9 |
Correct |
53 ms |
7272 KB |
Output is correct |
10 |
Correct |
49 ms |
7272 KB |
Output is correct |
11 |
Correct |
66 ms |
7272 KB |
Output is correct |
12 |
Correct |
66 ms |
7272 KB |
Output is correct |