#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 500100;
const ll INF = 1e18;
const ll MOD = 1e9+7;
pi A[MAXN];
vpi V;
ll N,a,b;
struct node{
ll s,e,m,v,lazy;
node *l,*r;
node(int _s,int _e):s(_s), e(_e){
m=(s+e)/2;v=-V[s].f;lazy=0;
// cout<<"Original "<<v<<' '<<V[]
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
v=max(l->v,r->v);
}
}
void up(int x, int y, int val){
if (s==x&&e==y){lazy+=val;return;}
if (y<=m)l->up(x,y,val);
else if (x>m)r->up(x,y,val);
else {l->up(x,m,val);r->up(m+1,y,val);}
v=max(l->v+l->lazy, r->v+r->lazy);
}
ll query(ll x, ll y){
if (s==x&&e==y)return v+lazy;
if (y<=m)return l->query(x,y);
if (x>m)return r->query(x,y);
return max(l->query(x,m), r->query(m+1,y));
}
}*root;
int main(){
cin>>N;
for (int i=1;i<=N;++i){
cin>>A[i].f>>A[i].s;
}
sort(A+1,A+N+1);
for(int i=1;i<=N;++i){
if (SZ(V) && V.back().f == A[i].f){
V.back().s += A[i].s;
}else V.pb(A[i]);
}
ll ans = 0;
N = SZ(V);
root = new node(0,N-1);
for (int i=0;i<N;++i){
// cout<<i<<' '<<V[i].s<<'\n';
root->up(i,N-1,V[i].s);
}
for (int i=0;i<N;++i){
ll offset = V[i].s+V[i].f;
// cout<<"At "<<V[i].f<< " offset is "<<offset<<'\n';
root->up(i,N-1,-V[i].s);
ll v = root->query(i,N-1);
// cout<<"Value "<<v<<'\n';
ans=max(ans,v+offset);
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
14 ms |
1152 KB |
Output is correct |
28 |
Correct |
18 ms |
1152 KB |
Output is correct |
29 |
Correct |
14 ms |
1152 KB |
Output is correct |
30 |
Correct |
14 ms |
1152 KB |
Output is correct |
31 |
Correct |
14 ms |
1152 KB |
Output is correct |
32 |
Correct |
14 ms |
1152 KB |
Output is correct |
33 |
Correct |
14 ms |
1152 KB |
Output is correct |
34 |
Correct |
14 ms |
1152 KB |
Output is correct |
35 |
Correct |
14 ms |
1152 KB |
Output is correct |
36 |
Correct |
14 ms |
1152 KB |
Output is correct |
37 |
Correct |
15 ms |
1152 KB |
Output is correct |
38 |
Correct |
16 ms |
1152 KB |
Output is correct |
39 |
Correct |
14 ms |
1152 KB |
Output is correct |
40 |
Correct |
14 ms |
1152 KB |
Output is correct |
41 |
Correct |
14 ms |
1152 KB |
Output is correct |
42 |
Correct |
14 ms |
1152 KB |
Output is correct |
43 |
Correct |
14 ms |
1152 KB |
Output is correct |
44 |
Correct |
14 ms |
1152 KB |
Output is correct |
45 |
Correct |
14 ms |
1152 KB |
Output is correct |
46 |
Correct |
14 ms |
1152 KB |
Output is correct |
47 |
Correct |
14 ms |
1152 KB |
Output is correct |
48 |
Correct |
14 ms |
1152 KB |
Output is correct |
49 |
Correct |
14 ms |
1152 KB |
Output is correct |
50 |
Correct |
14 ms |
1152 KB |
Output is correct |
51 |
Correct |
14 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
14 ms |
1152 KB |
Output is correct |
28 |
Correct |
18 ms |
1152 KB |
Output is correct |
29 |
Correct |
14 ms |
1152 KB |
Output is correct |
30 |
Correct |
14 ms |
1152 KB |
Output is correct |
31 |
Correct |
14 ms |
1152 KB |
Output is correct |
32 |
Correct |
14 ms |
1152 KB |
Output is correct |
33 |
Correct |
14 ms |
1152 KB |
Output is correct |
34 |
Correct |
14 ms |
1152 KB |
Output is correct |
35 |
Correct |
14 ms |
1152 KB |
Output is correct |
36 |
Correct |
14 ms |
1152 KB |
Output is correct |
37 |
Correct |
15 ms |
1152 KB |
Output is correct |
38 |
Correct |
16 ms |
1152 KB |
Output is correct |
39 |
Correct |
14 ms |
1152 KB |
Output is correct |
40 |
Correct |
14 ms |
1152 KB |
Output is correct |
41 |
Correct |
14 ms |
1152 KB |
Output is correct |
42 |
Correct |
14 ms |
1152 KB |
Output is correct |
43 |
Correct |
14 ms |
1152 KB |
Output is correct |
44 |
Correct |
14 ms |
1152 KB |
Output is correct |
45 |
Correct |
14 ms |
1152 KB |
Output is correct |
46 |
Correct |
14 ms |
1152 KB |
Output is correct |
47 |
Correct |
14 ms |
1152 KB |
Output is correct |
48 |
Correct |
14 ms |
1152 KB |
Output is correct |
49 |
Correct |
14 ms |
1152 KB |
Output is correct |
50 |
Correct |
14 ms |
1152 KB |
Output is correct |
51 |
Correct |
14 ms |
1152 KB |
Output is correct |
52 |
Execution timed out |
1006 ms |
78660 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |