#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
const int N = 1e6+12,INF=1e9+7;
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;
else {
int m = l+r>>1;
if (pos > m){
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_ans(int v,int l,int r,int x){
if (l == r)ret l;
int m = l+r>>1;
int a = der[v<<1];
int b = der[(v<<1)+1];
if (x <= b)ret get_ans((v<<1)+1,m+1,r,x);
else ret get_ans(v<<1,l,m,x);
}
main(){
int n,i,j,ans=0;
scan1(n)
for (i=1;i<=n;++i){
int b,c;
scan3(x[i],b,c)
p[i] = p[i-1]+c;
g[i] = g[i-1]+b;
update(1,1,n,i,p[i]-x[i]);
}
for (i=1;i<=n;++i){
int j = get_ans(1,1,n,p[i-1]-x[i]);
ans = max(ans,g[j]-g[i-1]);
}
cout <<ans;
}
Compilation message
divide.cpp: In function 'void update(int, int, int, int, int)':
divide.cpp:28:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int m = l+r>>1;
| ~^~
divide.cpp: In function 'int get_ans(int, int, int, int)':
divide.cpp:40:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | int m = l+r>>1;
| ~^~
divide.cpp:41:9: warning: unused variable 'a' [-Wunused-variable]
41 | int a = der[v<<1];
| ^
divide.cpp: At global scope:
divide.cpp:49:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | main(){
| ^
divide.cpp: In function 'int main()':
divide.cpp:51:13: warning: unused variable 'j' [-Wunused-variable]
51 | int n,i,j,ans=0;
| ^
divide.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
14 | #define scan1(a) scanf("%d",&a);
| ~~~~~^~~~~~~~~
divide.cpp:52:5: note: in expansion of macro 'scan1'
52 | scan1(n)
| ^~~~~
divide.cpp:16:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
16 | #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
divide.cpp:55:9: note: in expansion of macro 'scan3'
55 | scan3(x[i],b,c)
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |