#include<bits/stdc++.h>
using namespace std;
const int mx=1e5+5;
typedef long long ll;
int inf=1e9+10;
const int mod=1e9+7;
int d[mx];
int g[mx];
int x[mx];
ll pref[mx];
ll pref2[mx];
int n,m;
ll sum=0;
ll seg[4*mx];
void build(int node,int st,int en){
if(st==en){
seg[node]=pref[st];
return ;
}
int mid=(st+en)/2;
build(node*2,st,mid); build(node*2+1,mid+1,en);
seg[node]=max(seg[node*2],seg[node*2+1]);
}
void update(int node,int st,int en,int idx){
if(st>idx||en<idx){return;}
if(st==en){
seg[node]=-1e17;
return ;
}
int mid=(st+en)/2;
update(node*2,st,mid,idx);
update(node*2+1,mid+1,en,idx);
seg[node]=max(seg[node*2],seg[node*2+1]);
return ;
}
int query(int node,int st,int en){
if(st==en){
return st;
}
int mid=(st+en)/2;
if((seg[node*2+1]+sum)>=0){
return query(node*2+1,mid+1,en);
}else{
return query(node*2,st,mid);
}
}
int main(){
cin>>n;
ll ans=0;
for(int i=1;i<=n;i++){
cin>>x[i]>>g[i]>>d[i];
pref[i]=pref[i-1]+d[i];
pref2[i]=g[i]+pref2[i-1];
}
for(int i=1;i<=n;i++){
pref[i]=pref[i-1]+d[i];
if(i>1){
pref[i]-=(x[i]-x[i-1]);
}
//cout<<pref[i]<<" ";
}
//cout<<endl;
ll sum2=0;
int j=0;
build(1,1,n);
x[0]=x[1];
for(int i=1;i<=n;i++){
sum+=(x[i]-x[i-1])-d[i-1];
int l=query(1,1,n);
ans=max(pref2[l]-pref2[i-1],ans);
//cout<<l;
update(1,1,n,i);
}
cout<<ans;
}
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:83:5: warning: unused variable 'sum2' [-Wunused-variable]
83 | ll sum2=0;
| ^~~~
divide.cpp:84:6: warning: unused variable 'j' [-Wunused-variable]
84 | int j=0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 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 |
332 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
4 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
3 ms |
332 KB |
Output is correct |
22 |
Correct |
5 ms |
332 KB |
Output is correct |
23 |
Correct |
8 ms |
588 KB |
Output is correct |
24 |
Correct |
9 ms |
648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 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 |
332 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
4 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
3 ms |
332 KB |
Output is correct |
22 |
Correct |
5 ms |
332 KB |
Output is correct |
23 |
Correct |
8 ms |
588 KB |
Output is correct |
24 |
Correct |
9 ms |
648 KB |
Output is correct |
25 |
Correct |
7 ms |
588 KB |
Output is correct |
26 |
Correct |
10 ms |
772 KB |
Output is correct |
27 |
Correct |
15 ms |
844 KB |
Output is correct |
28 |
Correct |
75 ms |
2700 KB |
Output is correct |
29 |
Correct |
74 ms |
3968 KB |
Output is correct |
30 |
Correct |
184 ms |
7908 KB |
Output is correct |
31 |
Correct |
125 ms |
6840 KB |
Output is correct |
32 |
Correct |
124 ms |
6880 KB |
Output is correct |
33 |
Correct |
119 ms |
6708 KB |
Output is correct |
34 |
Correct |
125 ms |
6588 KB |
Output is correct |
35 |
Correct |
136 ms |
7172 KB |
Output is correct |
36 |
Correct |
141 ms |
7388 KB |
Output is correct |