#include<bits/stdc++.h>
using namespace std;
const int N=5e5;
int n;
pair<long long,long long>p[N+5];
long long inf=1e18,res=-inf;
struct SegmentTree{
long long st[N*4+5],lazy[N*4+5];
void down(int id) {
long long t=lazy[id];
if (t==0) return;
lazy[id]=0;
lazy[id*2]+=t;
st[id*2]+=t;
lazy[id*2+1]+=t;
st[id*2+1]+=t;
}
void update(int id,int l,int r,int u,int v,long long val) {
if (l>v||r<u||u>v) return;
if (u<=l&&r<=v) {
st[id]+=val;
lazy[id]+=val;
return;
}
down(id);
int mid=(l+r)/2;
update(id*2,l,mid,u,v,val);
update(id*2+1,mid+1,r,u,v,val);
st[id]=max(st[id*2],st[id*2+1]);
}
long long get(int id,int l,int r,int u,int v) {
if (l>v||r<u||u>v) return -inf;
if (u<=l&&r<=v) return st[id];
down(id);
int mid=(l+r)/2;
return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));
}
} tree;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n;
for (int i=1;i<=n;i++) {
cin>>p[i].first>>p[i].second;
res=max(res,p[i].second);
}
sort(p+1,p+1+n);
for (int i=1;i<=n;i++) {
tree.update(1,1,n,i,i,p[i].first+p[i].second);
tree.update(1,1,n,1,i-1,p[i].second);
res=max(res,-p[i].first+tree.get(1,1,n,1,i-1));
//cout<<p[i].first<<' '<<p[i].second<<' '<<res<<endl;
}
cout<<res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2552 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2552 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2552 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2552 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2384 KB |
Output is correct |
22 |
Correct |
1 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2552 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2552 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2384 KB |
Output is correct |
22 |
Correct |
1 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2384 KB |
Output is correct |
27 |
Correct |
5 ms |
2896 KB |
Output is correct |
28 |
Correct |
4 ms |
2896 KB |
Output is correct |
29 |
Correct |
3 ms |
2896 KB |
Output is correct |
30 |
Correct |
4 ms |
2896 KB |
Output is correct |
31 |
Correct |
4 ms |
2896 KB |
Output is correct |
32 |
Correct |
4 ms |
2896 KB |
Output is correct |
33 |
Correct |
4 ms |
2896 KB |
Output is correct |
34 |
Correct |
4 ms |
2640 KB |
Output is correct |
35 |
Correct |
5 ms |
2640 KB |
Output is correct |
36 |
Correct |
3 ms |
2896 KB |
Output is correct |
37 |
Correct |
4 ms |
3060 KB |
Output is correct |
38 |
Correct |
3 ms |
2896 KB |
Output is correct |
39 |
Correct |
4 ms |
2896 KB |
Output is correct |
40 |
Correct |
4 ms |
2640 KB |
Output is correct |
41 |
Correct |
5 ms |
2896 KB |
Output is correct |
42 |
Correct |
4 ms |
2884 KB |
Output is correct |
43 |
Correct |
4 ms |
2736 KB |
Output is correct |
44 |
Correct |
3 ms |
2896 KB |
Output is correct |
45 |
Correct |
3 ms |
2908 KB |
Output is correct |
46 |
Correct |
4 ms |
2896 KB |
Output is correct |
47 |
Correct |
3 ms |
2896 KB |
Output is correct |
48 |
Correct |
4 ms |
2892 KB |
Output is correct |
49 |
Correct |
4 ms |
2896 KB |
Output is correct |
50 |
Correct |
4 ms |
2896 KB |
Output is correct |
51 |
Correct |
4 ms |
2888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2552 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2552 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2384 KB |
Output is correct |
22 |
Correct |
1 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2384 KB |
Output is correct |
27 |
Correct |
5 ms |
2896 KB |
Output is correct |
28 |
Correct |
4 ms |
2896 KB |
Output is correct |
29 |
Correct |
3 ms |
2896 KB |
Output is correct |
30 |
Correct |
4 ms |
2896 KB |
Output is correct |
31 |
Correct |
4 ms |
2896 KB |
Output is correct |
32 |
Correct |
4 ms |
2896 KB |
Output is correct |
33 |
Correct |
4 ms |
2896 KB |
Output is correct |
34 |
Correct |
4 ms |
2640 KB |
Output is correct |
35 |
Correct |
5 ms |
2640 KB |
Output is correct |
36 |
Correct |
3 ms |
2896 KB |
Output is correct |
37 |
Correct |
4 ms |
3060 KB |
Output is correct |
38 |
Correct |
3 ms |
2896 KB |
Output is correct |
39 |
Correct |
4 ms |
2896 KB |
Output is correct |
40 |
Correct |
4 ms |
2640 KB |
Output is correct |
41 |
Correct |
5 ms |
2896 KB |
Output is correct |
42 |
Correct |
4 ms |
2884 KB |
Output is correct |
43 |
Correct |
4 ms |
2736 KB |
Output is correct |
44 |
Correct |
3 ms |
2896 KB |
Output is correct |
45 |
Correct |
3 ms |
2908 KB |
Output is correct |
46 |
Correct |
4 ms |
2896 KB |
Output is correct |
47 |
Correct |
3 ms |
2896 KB |
Output is correct |
48 |
Correct |
4 ms |
2892 KB |
Output is correct |
49 |
Correct |
4 ms |
2896 KB |
Output is correct |
50 |
Correct |
4 ms |
2896 KB |
Output is correct |
51 |
Correct |
4 ms |
2888 KB |
Output is correct |
52 |
Correct |
283 ms |
35144 KB |
Output is correct |
53 |
Correct |
291 ms |
31816 KB |
Output is correct |
54 |
Correct |
293 ms |
35140 KB |
Output is correct |
55 |
Correct |
291 ms |
25160 KB |
Output is correct |
56 |
Correct |
298 ms |
35024 KB |
Output is correct |
57 |
Correct |
292 ms |
31832 KB |
Output is correct |
58 |
Correct |
292 ms |
25040 KB |
Output is correct |
59 |
Correct |
274 ms |
31816 KB |
Output is correct |
60 |
Correct |
272 ms |
35280 KB |
Output is correct |
61 |
Correct |
281 ms |
31560 KB |
Output is correct |
62 |
Correct |
274 ms |
35144 KB |
Output is correct |
63 |
Correct |
286 ms |
31876 KB |
Output is correct |
64 |
Correct |
280 ms |
31704 KB |
Output is correct |
65 |
Correct |
290 ms |
35100 KB |
Output is correct |
66 |
Correct |
283 ms |
35056 KB |
Output is correct |
67 |
Correct |
292 ms |
31844 KB |
Output is correct |
68 |
Correct |
296 ms |
36536 KB |
Output is correct |