#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
ll t[400001];
ll n;
ll prefg[100001];
ll prefe[100001];
ll a[100001];
void update(ll v,ll tl,ll tr,ll pos,ll x){
if(tl==tr){
t[v]=x;
return;
}
else{
ll m=(tl+tr)/2;
if(pos<=m){
update(2*v,tl,m,pos,x);
}
else{
update(2*v+1,m+1,tr,pos,x);
}
t[v]=max(t[2*v],t[2*v+1]);
}
}
ll get(ll v,ll tl,ll tr,ll x){
if(tl==tr){
return tl;
}
ll f1=t[2*v];
ll f2=t[2*v+1];
ll m=(tl+tr)/2;
ll pas=0;
if(f2>=x){
pas=get(2*v+1,m+1,tr,x);
}
else{
if(f1>=x){
pas=get(2*v,tl,m,x);
}
else{
pas=-1;;
}
}
return pas;
}
int main(){
cin>>n;
for(ll k=1;k<=n;k++){
ll x,y,z;
cin>>x>>y>>z;
a[k]=x;
prefe[k]=prefe[k-1]+z;
prefg[k]=prefg[k-1]+y;
ll f=prefe[k]-a[k];
update(1,1,n,k,f);
}
ll mx=0;
for(ll k=1;k<=n;k++){
ll f=prefe[k-1]-a[k];
ll ind=get(1,1,n,f);
if(ind>=k){
ll gl=prefg[ind]-prefg[k-1];
mx=max(mx,gl);
}
}
cout<<mx;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
468 KB |
Output is correct |
24 |
Correct |
6 ms |
484 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
468 KB |
Output is correct |
24 |
Correct |
6 ms |
484 KB |
Output is correct |
25 |
Correct |
4 ms |
468 KB |
Output is correct |
26 |
Correct |
7 ms |
740 KB |
Output is correct |
27 |
Correct |
9 ms |
980 KB |
Output is correct |
28 |
Correct |
47 ms |
3492 KB |
Output is correct |
29 |
Correct |
54 ms |
3688 KB |
Output is correct |
30 |
Correct |
120 ms |
7580 KB |
Output is correct |
31 |
Correct |
87 ms |
6404 KB |
Output is correct |
32 |
Correct |
92 ms |
6452 KB |
Output is correct |
33 |
Correct |
86 ms |
6196 KB |
Output is correct |
34 |
Correct |
85 ms |
6288 KB |
Output is correct |
35 |
Correct |
103 ms |
6828 KB |
Output is correct |
36 |
Correct |
133 ms |
6948 KB |
Output is correct |