#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 2e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int a[N], n, m, k;
int prd[N];
int prg[N];
int mx[N*4];
void update(int pos, int L, int R, int x, int val){
if(L == R){
mx[x] = val;
//~ cout << L << ' ' << val << '\n';
return;
}int mid = (L+R)/2;
if(mid >= pos)update(pos, L, mid, x*2, val);
else update(pos, mid+1, R, x*2+1, val);
mx[x] = max(mx[x*2], mx[x*2+1]);
}
int tmp;
int get(int l, int r, int L, int R, int x){
if(L > r || R < l)return 0;
if(L == R){
if(mx[x] >= tmp)return L;
else return 0;
}
int mid = (L+R)/2;
if(L >= l && R <= r){
if(mx[x*2+1] >= tmp)return get(l, r, mid+1, R, x*2+1);
else return get(l, r, L, mid, x*2);
}
return max(get(l, r, L, mid, x*2), get(l, r, mid+1, R, x*2+1));
}
void solve(int test_case){
int i, j;
vector<tuple<int, int, int>> v;
cin >> n;
v.pb(make_tuple(0,0,0));
for(i=0;i<n;i++){
int x, g, d;
cin >> x >> g >> d;
v.pb(make_tuple(x, g, d));
}
//~ sort(all(v));
for(i=1;i<=n;i++){
prd[i] = prd[i-1] + get<2>(v[i]);
prg[i] = prg[i-1] + get<1>(v[i]);
update(i, 1, n, 1, prd[i] - get<0>(v[i]));
}
tmp = -mod;
int ans = 0;
for(i=1;i<=n;i++){
tmp = prd[i-1] - get<0>(v[i]);
int t = get(i, n, 1, n, 1);
chmax(ans, prg[t] - prg[i-1]);
}
cout << ans << '\n';
return;
}
signed main(){
FASTIO;
#define MULTITEST 0
#if MULTITEST
int _T;
cin >> _T;
for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
Compilation message
divide.cpp: In function 'void solve(long long int)':
divide.cpp:45:9: warning: unused variable 'j' [-Wunused-variable]
45 | int i, j;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 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 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 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 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
4 ms |
812 KB |
Output is correct |
24 |
Correct |
4 ms |
812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 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 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
4 ms |
812 KB |
Output is correct |
24 |
Correct |
4 ms |
812 KB |
Output is correct |
25 |
Correct |
4 ms |
812 KB |
Output is correct |
26 |
Correct |
8 ms |
1128 KB |
Output is correct |
27 |
Correct |
8 ms |
1128 KB |
Output is correct |
28 |
Correct |
43 ms |
3424 KB |
Output is correct |
29 |
Correct |
50 ms |
3424 KB |
Output is correct |
30 |
Correct |
96 ms |
6492 KB |
Output is correct |
31 |
Correct |
88 ms |
6528 KB |
Output is correct |
32 |
Correct |
89 ms |
6492 KB |
Output is correct |
33 |
Correct |
93 ms |
6492 KB |
Output is correct |
34 |
Correct |
77 ms |
6492 KB |
Output is correct |
35 |
Correct |
79 ms |
6492 KB |
Output is correct |
36 |
Correct |
82 ms |
6492 KB |
Output is correct |