#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <array>
using namespace std;
typedef long long ll;
const int maxn=1e5+5, Log=17, pot=(1<<Log);
struct tournament{
ll t[pot*2], prop[pot*2];
void propagate(int x){
if(!prop[x]){
return;
}
t[x]+=prop[x];
if(x<pot){
prop[x*2]+=prop[x];
prop[x*2+1]+=prop[x];
}
prop[x]=0;
}
void update(int x, int val){
t[x]+=val;
for(x/=2; x>0; x/=2){
propagate(x*2);
propagate(x*2+1);
t[x]=min(t[x*2], t[x*2+1]);
}
}
void update2(int L, int D, int x, int l, int d, int val){
propagate(x);
if(L>=l && D<=d){
// cout << "na " << L << ' ' << D << endl;
update(x, val);
if(x<pot){
prop[x*2]+=val;
prop[x*2+1]+=val;
}
return;
}
if((L+D)/2>=l){
update2(L, (L+D)/2, x*2, l, d, val);
}
if((L+D)/2+1<=d){
update2((L+D)/2+1, D, x*2+1, l, d, val);
}
}
int query(int x){
// cout << x << ' ' << t[x] << endl;
if(x>=pot){
return x;
}
propagate(x*2);
propagate(x*2+1);
if(t[x*2]<=0){
return query(x*2);
}
return query(x*2+1);
}
};
/*
struct logaritamska{
ll l[maxn];
void update(int x, int val){
for(; x<maxn; x+=(x & -x)){
l[x]+=val;
}
}
ll query(int x){
ll sol=0;
for(; x>0; x-=(x & -x)){
sol+=l[x];
}
return sol;
}
};
inline int rev(int x){
return maxn-x-1;
}
logaritamska L;*/
tournament T;
int l[maxn][3];
ll pref[maxn];
/*
int binary(int x){
int lo=0, hi=x, mid;
while(lo<hi){
mid=(lo+hi)/2;
if(L.query(rev(mid))>0){
lo=mid+1;
}
else{
hi=mid;
}
}
return lo;
}*/
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i=0; i<n; i++){
cin >> l[i][0] >> l[i][1] >> l[i][2];
pref[i+1]=pref[i]+l[i][1];
}
int pos;
ll val=0;
for(int i=0; i<n; i++){
T.update2(0, pot-1, 1, 0, i, -l[i][2]);
if(i){
T.update2(0, pot-1, 1, 0, i-1, l[i][0]-l[i-1][0]);
}
pos=T.query(1)-pot;
val=max(val, pref[i+1]-pref[pos]);
// cout << i << ' ' << pos << endl;
}
cout << val << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
3 ms |
460 KB |
Output is correct |
23 |
Correct |
7 ms |
724 KB |
Output is correct |
24 |
Correct |
7 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
3 ms |
460 KB |
Output is correct |
23 |
Correct |
7 ms |
724 KB |
Output is correct |
24 |
Correct |
7 ms |
716 KB |
Output is correct |
25 |
Correct |
7 ms |
716 KB |
Output is correct |
26 |
Correct |
14 ms |
1008 KB |
Output is correct |
27 |
Correct |
17 ms |
1104 KB |
Output is correct |
28 |
Correct |
82 ms |
3884 KB |
Output is correct |
29 |
Correct |
95 ms |
3820 KB |
Output is correct |
30 |
Correct |
158 ms |
7128 KB |
Output is correct |
31 |
Correct |
135 ms |
6412 KB |
Output is correct |
32 |
Correct |
162 ms |
6340 KB |
Output is correct |
33 |
Correct |
168 ms |
6408 KB |
Output is correct |
34 |
Correct |
128 ms |
6396 KB |
Output is correct |
35 |
Correct |
141 ms |
6408 KB |
Output is correct |
36 |
Correct |
130 ms |
6544 KB |
Output is correct |