This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define ret return
#define fr first
#define sc second
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define nosol puts("-1");
#define pb push_back
#define endi puts("");
const int N = 1e6+12,INF = 1e15+7;
#define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int p[N],der[N],g[N],x[N];
void update(int v,int l,int r,int pos,int x){
if (l == r){
der[v] = x;
ret ;
}
int m = l+r>>1;
if (m < pos){
update((v<<1)+1,m+1,r,pos,x);
}
else update(v<<1,l,m,pos,x);
der[v] = max(der[v<<1],der[(v<<1)+1]);
}
int get_pos(int v,int l,int r,int x){
if (l == r)ret l;
int m = l+r>>1;
if (der[(v<<1)+1] >= x)ret get_pos((v<<1)+1,m+1,r,x);
ret get_pos(v<<1,l,m,x);
}
main(){
int n,i,a,b,ans=0;
cin>>n;
for (i=1;i<=n;++i){
cin>>x[i]>>a>>b;
g[i] = g[i-1]+a;
p[i] = p[i-1]+b;
update(1,1,n,i,p[i]-x[i]);
}
for (i=1;i<=n;++i){
int j = get_pos(1,1,n,p[i-1]-x[i]);
ans = max(ans,g[j]-g[i-1]);
}
cout <<ans;
}
Compilation message (stderr)
divide.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
divide.cpp:28:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int m = l+r>>1;
| ~^~
divide.cpp: In function 'long long int get_pos(long long int, long long int, long long int, long long int)':
divide.cpp:38:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | int m = l+r>>1;
| ~^~
divide.cpp: At global scope:
divide.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
44 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |