#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
using namespace std;
vector<int>x(200001),d(200001);
vector<ll>g(200001);
vector<int>t(800001,1e18+1);
void update(int v,int l,int r,int val,int pos){
if(l==r){
t[v]=val;
return;
}
int m=(l+r)/2;
if(pos<=m)update(2*v,l,m,val,pos);
if(pos>m)update(2*v+1,m+1,r,val,pos);
t[v]=min(t[2*v],t[2*v+1]);
}
int get(int v,int l,int r,int val){
if(l==r){
return l;
}
int m=(l+r)/2;
if(t[2*v]<=val)return get(2*v,l,m,val);
if(t[2*v+1]<=val)return get(2*v+1,m+1,r,val);
return -1;
}
void solve(){
int n;cin>>n;
vector<ll>pref(n+1);
pref[0]=0;
for(int i=1;i<=n;i++){
cin>>x[i]>>g[i]>>d[i];
d[i]+=d[i-1];
pref[i]=pref[i-1]+g[i];
}
ll mx=0;
for(int i=1;i<=n;i++){
update(1,1,n,d[i-1]-x[i],i);
int ind=get(1,1,n,d[i]-x[i]);
mx=max(mx,pref[i]-pref[ind-1]);
}
cout<<mx;
}
int main(){
solve();
}
Compilation message
divide.cpp:14:25: warning: overflow in conversion from 'double' to 'std::vector<int>::value_type' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
14 | vector<int>t(800001,1e18+1);
| ~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6476 KB |
Output is correct |
2 |
Correct |
4 ms |
6476 KB |
Output is correct |
3 |
Correct |
4 ms |
6580 KB |
Output is correct |
4 |
Correct |
5 ms |
6476 KB |
Output is correct |
5 |
Correct |
4 ms |
6476 KB |
Output is correct |
6 |
Correct |
4 ms |
6476 KB |
Output is correct |
7 |
Correct |
4 ms |
6476 KB |
Output is correct |
8 |
Correct |
4 ms |
6476 KB |
Output is correct |
9 |
Correct |
4 ms |
6476 KB |
Output is correct |
10 |
Correct |
5 ms |
6476 KB |
Output is correct |
11 |
Correct |
4 ms |
6476 KB |
Output is correct |
12 |
Correct |
4 ms |
6476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6476 KB |
Output is correct |
2 |
Correct |
4 ms |
6476 KB |
Output is correct |
3 |
Correct |
4 ms |
6580 KB |
Output is correct |
4 |
Correct |
5 ms |
6476 KB |
Output is correct |
5 |
Correct |
4 ms |
6476 KB |
Output is correct |
6 |
Correct |
4 ms |
6476 KB |
Output is correct |
7 |
Correct |
4 ms |
6476 KB |
Output is correct |
8 |
Correct |
4 ms |
6476 KB |
Output is correct |
9 |
Correct |
4 ms |
6476 KB |
Output is correct |
10 |
Correct |
5 ms |
6476 KB |
Output is correct |
11 |
Correct |
4 ms |
6476 KB |
Output is correct |
12 |
Correct |
4 ms |
6476 KB |
Output is correct |
13 |
Correct |
4 ms |
6568 KB |
Output is correct |
14 |
Correct |
4 ms |
6476 KB |
Output is correct |
15 |
Correct |
5 ms |
6476 KB |
Output is correct |
16 |
Correct |
5 ms |
6476 KB |
Output is correct |
17 |
Correct |
5 ms |
6492 KB |
Output is correct |
18 |
Incorrect |
6 ms |
6504 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6476 KB |
Output is correct |
2 |
Correct |
4 ms |
6476 KB |
Output is correct |
3 |
Correct |
4 ms |
6580 KB |
Output is correct |
4 |
Correct |
5 ms |
6476 KB |
Output is correct |
5 |
Correct |
4 ms |
6476 KB |
Output is correct |
6 |
Correct |
4 ms |
6476 KB |
Output is correct |
7 |
Correct |
4 ms |
6476 KB |
Output is correct |
8 |
Correct |
4 ms |
6476 KB |
Output is correct |
9 |
Correct |
4 ms |
6476 KB |
Output is correct |
10 |
Correct |
5 ms |
6476 KB |
Output is correct |
11 |
Correct |
4 ms |
6476 KB |
Output is correct |
12 |
Correct |
4 ms |
6476 KB |
Output is correct |
13 |
Correct |
4 ms |
6568 KB |
Output is correct |
14 |
Correct |
4 ms |
6476 KB |
Output is correct |
15 |
Correct |
5 ms |
6476 KB |
Output is correct |
16 |
Correct |
5 ms |
6476 KB |
Output is correct |
17 |
Correct |
5 ms |
6492 KB |
Output is correct |
18 |
Incorrect |
6 ms |
6504 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |