#include <iostream>
using namespace std;
const long long maxN = 1e5 + 5, inf = 1e18;
pair<int, pair<int, int> > arr[maxN];
long long sg[4*maxN], pref_diff[maxN], pref_gold[maxN];
void build(int idx, int nl, int nr){
if (nl == nr){
sg[idx] = pref_diff[nl];
return;
}
int mid = (nl + nr)/2;
build(2*idx, nl, mid);
build(2*idx+1, mid+1, nr);
sg[idx] = max(sg[2*idx], sg[2*idx+1]);
}
int query(int idx, int nl, int nr, int need){
if (nl == nr) return nl;
int mid = (nl + nr)/2;
if (sg[2*idx+1] >= need) return query(2*idx+1, mid+1, nr, need);
return query(2*idx, nl, mid, need);
}
int main(){
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second.first >> arr[i].second.second;
pref_diff[0] = arr[0].second.second;
for (int i = 1; i < n; i++) pref_diff[i] = pref_diff[i-1] + arr[i].second.second - (arr[i].first - arr[i-1].first);
pref_gold[0] = arr[0].second.first;
for (int i = 1; i < n; i++) pref_gold[i] = pref_gold[i-1] + arr[i].second.first;
build(1, 0, n-1);
long long mx = pref_gold[query(1, 0, n-1, 0)];
for (int i = 1; i < n; i++){
long long cur = pref_gold[query(1, 0, n-1, pref_diff[i]-arr[i].second.second)] - pref_gold[i-1];
mx = max(cur, mx);
}
cout << mx << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
680 KB |
Output is correct |
24 |
Correct |
5 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
680 KB |
Output is correct |
24 |
Correct |
5 ms |
596 KB |
Output is correct |
25 |
Correct |
4 ms |
636 KB |
Output is correct |
26 |
Correct |
6 ms |
956 KB |
Output is correct |
27 |
Correct |
8 ms |
980 KB |
Output is correct |
28 |
Correct |
44 ms |
3660 KB |
Output is correct |
29 |
Correct |
54 ms |
3992 KB |
Output is correct |
30 |
Correct |
123 ms |
7976 KB |
Output is correct |
31 |
Correct |
100 ms |
6796 KB |
Output is correct |
32 |
Correct |
82 ms |
6844 KB |
Output is correct |
33 |
Correct |
75 ms |
6716 KB |
Output is correct |
34 |
Correct |
76 ms |
6628 KB |
Output is correct |
35 |
Correct |
96 ms |
7180 KB |
Output is correct |
36 |
Correct |
104 ms |
7324 KB |
Output is correct |