#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);
const int N=100010;
int n;
int x[N],g[N],s[N],bit[N];
vector<int> val;
void upd(int i,int x){
i=lower_bound(all(val),i)-val.begin()+1;
for(;i;i-=i&-i) bit[i]=min(bit[i],x);
}
int que(int i){
i=lower_bound(all(val),i)-val.begin()+1;
int ret=bit[0];
for(;i<=n;i+=i&-i) ret=min(ret,bit[i]);
return ret;
}
main(){
#define task "dnc"
//freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
n=in;
forinc(i,1,n){
x[i]=in;
g[i]=g[i-1]+in;
s[i]=s[i-1]+in;
val.push_back(x[i]-s[i-1]);
}
/**
x[i] - x[j] <= s[i] - s[j-1]
x[i]-s[i] <= x[j]-s[j-1]
g[i]-g[j-1] = max
*/
reset(bit,127);
int ret=0;
sort(all(val));
forinc(i,1,n){
upd(x[i]-s[i-1],g[i-1]);
ret=max(ret,g[i]-que(x[i]-s[i]));
}
cout<<ret;
}
Compilation message
divide.cpp:40:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
5 ms |
1152 KB |
Output is correct |
5 |
Correct |
5 ms |
1152 KB |
Output is correct |
6 |
Correct |
5 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
1152 KB |
Output is correct |
8 |
Correct |
5 ms |
1152 KB |
Output is correct |
9 |
Correct |
5 ms |
1152 KB |
Output is correct |
10 |
Correct |
5 ms |
1152 KB |
Output is correct |
11 |
Correct |
5 ms |
1152 KB |
Output is correct |
12 |
Correct |
5 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
5 ms |
1152 KB |
Output is correct |
5 |
Correct |
5 ms |
1152 KB |
Output is correct |
6 |
Correct |
5 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
1152 KB |
Output is correct |
8 |
Correct |
5 ms |
1152 KB |
Output is correct |
9 |
Correct |
5 ms |
1152 KB |
Output is correct |
10 |
Correct |
5 ms |
1152 KB |
Output is correct |
11 |
Correct |
5 ms |
1152 KB |
Output is correct |
12 |
Correct |
5 ms |
1152 KB |
Output is correct |
13 |
Correct |
5 ms |
1152 KB |
Output is correct |
14 |
Correct |
5 ms |
1152 KB |
Output is correct |
15 |
Correct |
5 ms |
1152 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
6 ms |
1152 KB |
Output is correct |
18 |
Correct |
5 ms |
1152 KB |
Output is correct |
19 |
Correct |
5 ms |
1152 KB |
Output is correct |
20 |
Correct |
5 ms |
1152 KB |
Output is correct |
21 |
Correct |
6 ms |
1152 KB |
Output is correct |
22 |
Correct |
6 ms |
1280 KB |
Output is correct |
23 |
Correct |
7 ms |
1536 KB |
Output is correct |
24 |
Correct |
8 ms |
1536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
5 ms |
1152 KB |
Output is correct |
5 |
Correct |
5 ms |
1152 KB |
Output is correct |
6 |
Correct |
5 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
1152 KB |
Output is correct |
8 |
Correct |
5 ms |
1152 KB |
Output is correct |
9 |
Correct |
5 ms |
1152 KB |
Output is correct |
10 |
Correct |
5 ms |
1152 KB |
Output is correct |
11 |
Correct |
5 ms |
1152 KB |
Output is correct |
12 |
Correct |
5 ms |
1152 KB |
Output is correct |
13 |
Correct |
5 ms |
1152 KB |
Output is correct |
14 |
Correct |
5 ms |
1152 KB |
Output is correct |
15 |
Correct |
5 ms |
1152 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
6 ms |
1152 KB |
Output is correct |
18 |
Correct |
5 ms |
1152 KB |
Output is correct |
19 |
Correct |
5 ms |
1152 KB |
Output is correct |
20 |
Correct |
5 ms |
1152 KB |
Output is correct |
21 |
Correct |
6 ms |
1152 KB |
Output is correct |
22 |
Correct |
6 ms |
1280 KB |
Output is correct |
23 |
Correct |
7 ms |
1536 KB |
Output is correct |
24 |
Correct |
8 ms |
1536 KB |
Output is correct |
25 |
Correct |
7 ms |
1408 KB |
Output is correct |
26 |
Correct |
8 ms |
1664 KB |
Output is correct |
27 |
Correct |
9 ms |
1792 KB |
Output is correct |
28 |
Correct |
27 ms |
3832 KB |
Output is correct |
29 |
Correct |
30 ms |
4088 KB |
Output is correct |
30 |
Correct |
61 ms |
7276 KB |
Output is correct |
31 |
Correct |
44 ms |
6132 KB |
Output is correct |
32 |
Correct |
45 ms |
6260 KB |
Output is correct |
33 |
Correct |
45 ms |
5992 KB |
Output is correct |
34 |
Correct |
44 ms |
6004 KB |
Output is correct |
35 |
Correct |
52 ms |
6652 KB |
Output is correct |
36 |
Correct |
54 ms |
6636 KB |
Output is correct |