#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
using namespace std;
const int mxn=5e5+5;
const ll inf=1e18;
struct segtree {
ll tree[4*mxn];
void init() {
for(int i=1;i<4*mxn;i++) tree[i]=-inf;
}
void update(int node,int b,int e,int p,ll v) {
if(e<p || b>p)return;
if(b==e) {
tree[node]=v;
return;
}
int mid=b+e>>1;
int left=node<<1;
int right=left|1;
update(left,b,mid,p,v);
update(right,mid+1,e,p,v);
tree[node]=max(tree[left],tree[right]);
}
} st;
int main() {
int n;
cin>>n;
pii a[n];
for(int i=0;i<n;i++) {
scanf("%lld %lld",&a[i].first,&a[i].second);
}
sort(a,a+n);
reverse(a,a+n);
st.init();
ll ps=0;
for(int i=0;i<n;i++) {
ps+=a[i].second;
st.update(1,1,n,i+1,ps+a[i].first);
}
ps=0;
ll ans=-inf;
for(int i=0;i<n;i++) {
ll v=st.tree[1];
v-=ps+a[i].first;
ans=max(ans,v);
st.update(1,1,n,i+1,-inf);
ps+=a[i].second;
}
cout<<ans<<endl;
}
Compilation message
art.cpp: In member function 'void segtree::update(int, int, int, int, long long int)':
art.cpp:21:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
21 | int mid=b+e>>1;
| ~^~
art.cpp: In function 'int main()':
art.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
38 | scanf("%lld %lld",&a[i].first,&a[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
16000 KB |
Output is correct |
2 |
Correct |
9 ms |
16000 KB |
Output is correct |
3 |
Correct |
9 ms |
16000 KB |
Output is correct |
4 |
Correct |
9 ms |
16000 KB |
Output is correct |
5 |
Correct |
10 ms |
16000 KB |
Output is correct |
6 |
Correct |
9 ms |
16000 KB |
Output is correct |
7 |
Correct |
9 ms |
16000 KB |
Output is correct |
8 |
Correct |
9 ms |
16000 KB |
Output is correct |
9 |
Correct |
9 ms |
16000 KB |
Output is correct |
10 |
Correct |
9 ms |
16000 KB |
Output is correct |
11 |
Correct |
10 ms |
16000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
16000 KB |
Output is correct |
2 |
Correct |
9 ms |
16000 KB |
Output is correct |
3 |
Correct |
9 ms |
16000 KB |
Output is correct |
4 |
Correct |
9 ms |
16000 KB |
Output is correct |
5 |
Correct |
10 ms |
16000 KB |
Output is correct |
6 |
Correct |
9 ms |
16000 KB |
Output is correct |
7 |
Correct |
9 ms |
16000 KB |
Output is correct |
8 |
Correct |
9 ms |
16000 KB |
Output is correct |
9 |
Correct |
9 ms |
16000 KB |
Output is correct |
10 |
Correct |
9 ms |
16000 KB |
Output is correct |
11 |
Correct |
10 ms |
16000 KB |
Output is correct |
12 |
Correct |
10 ms |
16032 KB |
Output is correct |
13 |
Correct |
10 ms |
16000 KB |
Output is correct |
14 |
Correct |
11 ms |
16000 KB |
Output is correct |
15 |
Correct |
10 ms |
16000 KB |
Output is correct |
16 |
Correct |
10 ms |
16000 KB |
Output is correct |
17 |
Correct |
9 ms |
16000 KB |
Output is correct |
18 |
Correct |
10 ms |
16000 KB |
Output is correct |
19 |
Correct |
9 ms |
16000 KB |
Output is correct |
20 |
Correct |
11 ms |
16000 KB |
Output is correct |
21 |
Correct |
10 ms |
16000 KB |
Output is correct |
22 |
Correct |
12 ms |
16000 KB |
Output is correct |
23 |
Correct |
10 ms |
16000 KB |
Output is correct |
24 |
Correct |
10 ms |
16000 KB |
Output is correct |
25 |
Correct |
10 ms |
16000 KB |
Output is correct |
26 |
Correct |
10 ms |
16000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
16000 KB |
Output is correct |
2 |
Correct |
9 ms |
16000 KB |
Output is correct |
3 |
Correct |
9 ms |
16000 KB |
Output is correct |
4 |
Correct |
9 ms |
16000 KB |
Output is correct |
5 |
Correct |
10 ms |
16000 KB |
Output is correct |
6 |
Correct |
9 ms |
16000 KB |
Output is correct |
7 |
Correct |
9 ms |
16000 KB |
Output is correct |
8 |
Correct |
9 ms |
16000 KB |
Output is correct |
9 |
Correct |
9 ms |
16000 KB |
Output is correct |
10 |
Correct |
9 ms |
16000 KB |
Output is correct |
11 |
Correct |
10 ms |
16000 KB |
Output is correct |
12 |
Correct |
10 ms |
16032 KB |
Output is correct |
13 |
Correct |
10 ms |
16000 KB |
Output is correct |
14 |
Correct |
11 ms |
16000 KB |
Output is correct |
15 |
Correct |
10 ms |
16000 KB |
Output is correct |
16 |
Correct |
10 ms |
16000 KB |
Output is correct |
17 |
Correct |
9 ms |
16000 KB |
Output is correct |
18 |
Correct |
10 ms |
16000 KB |
Output is correct |
19 |
Correct |
9 ms |
16000 KB |
Output is correct |
20 |
Correct |
11 ms |
16000 KB |
Output is correct |
21 |
Correct |
10 ms |
16000 KB |
Output is correct |
22 |
Correct |
12 ms |
16000 KB |
Output is correct |
23 |
Correct |
10 ms |
16000 KB |
Output is correct |
24 |
Correct |
10 ms |
16000 KB |
Output is correct |
25 |
Correct |
10 ms |
16000 KB |
Output is correct |
26 |
Correct |
10 ms |
16000 KB |
Output is correct |
27 |
Correct |
12 ms |
16000 KB |
Output is correct |
28 |
Correct |
14 ms |
16000 KB |
Output is correct |
29 |
Correct |
13 ms |
16000 KB |
Output is correct |
30 |
Correct |
13 ms |
16000 KB |
Output is correct |
31 |
Correct |
13 ms |
16000 KB |
Output is correct |
32 |
Correct |
13 ms |
16000 KB |
Output is correct |
33 |
Correct |
13 ms |
16000 KB |
Output is correct |
34 |
Correct |
13 ms |
16000 KB |
Output is correct |
35 |
Correct |
13 ms |
16000 KB |
Output is correct |
36 |
Correct |
13 ms |
16000 KB |
Output is correct |
37 |
Correct |
13 ms |
16000 KB |
Output is correct |
38 |
Correct |
13 ms |
16000 KB |
Output is correct |
39 |
Correct |
13 ms |
16000 KB |
Output is correct |
40 |
Correct |
13 ms |
16000 KB |
Output is correct |
41 |
Correct |
12 ms |
16000 KB |
Output is correct |
42 |
Correct |
13 ms |
16000 KB |
Output is correct |
43 |
Correct |
13 ms |
16000 KB |
Output is correct |
44 |
Correct |
13 ms |
16000 KB |
Output is correct |
45 |
Correct |
13 ms |
16000 KB |
Output is correct |
46 |
Correct |
13 ms |
16000 KB |
Output is correct |
47 |
Correct |
13 ms |
16000 KB |
Output is correct |
48 |
Correct |
13 ms |
16000 KB |
Output is correct |
49 |
Correct |
13 ms |
16256 KB |
Output is correct |
50 |
Correct |
16 ms |
16000 KB |
Output is correct |
51 |
Correct |
13 ms |
16000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
16000 KB |
Output is correct |
2 |
Correct |
9 ms |
16000 KB |
Output is correct |
3 |
Correct |
9 ms |
16000 KB |
Output is correct |
4 |
Correct |
9 ms |
16000 KB |
Output is correct |
5 |
Correct |
10 ms |
16000 KB |
Output is correct |
6 |
Correct |
9 ms |
16000 KB |
Output is correct |
7 |
Correct |
9 ms |
16000 KB |
Output is correct |
8 |
Correct |
9 ms |
16000 KB |
Output is correct |
9 |
Correct |
9 ms |
16000 KB |
Output is correct |
10 |
Correct |
9 ms |
16000 KB |
Output is correct |
11 |
Correct |
10 ms |
16000 KB |
Output is correct |
12 |
Correct |
10 ms |
16032 KB |
Output is correct |
13 |
Correct |
10 ms |
16000 KB |
Output is correct |
14 |
Correct |
11 ms |
16000 KB |
Output is correct |
15 |
Correct |
10 ms |
16000 KB |
Output is correct |
16 |
Correct |
10 ms |
16000 KB |
Output is correct |
17 |
Correct |
9 ms |
16000 KB |
Output is correct |
18 |
Correct |
10 ms |
16000 KB |
Output is correct |
19 |
Correct |
9 ms |
16000 KB |
Output is correct |
20 |
Correct |
11 ms |
16000 KB |
Output is correct |
21 |
Correct |
10 ms |
16000 KB |
Output is correct |
22 |
Correct |
12 ms |
16000 KB |
Output is correct |
23 |
Correct |
10 ms |
16000 KB |
Output is correct |
24 |
Correct |
10 ms |
16000 KB |
Output is correct |
25 |
Correct |
10 ms |
16000 KB |
Output is correct |
26 |
Correct |
10 ms |
16000 KB |
Output is correct |
27 |
Correct |
12 ms |
16000 KB |
Output is correct |
28 |
Correct |
14 ms |
16000 KB |
Output is correct |
29 |
Correct |
13 ms |
16000 KB |
Output is correct |
30 |
Correct |
13 ms |
16000 KB |
Output is correct |
31 |
Correct |
13 ms |
16000 KB |
Output is correct |
32 |
Correct |
13 ms |
16000 KB |
Output is correct |
33 |
Correct |
13 ms |
16000 KB |
Output is correct |
34 |
Correct |
13 ms |
16000 KB |
Output is correct |
35 |
Correct |
13 ms |
16000 KB |
Output is correct |
36 |
Correct |
13 ms |
16000 KB |
Output is correct |
37 |
Correct |
13 ms |
16000 KB |
Output is correct |
38 |
Correct |
13 ms |
16000 KB |
Output is correct |
39 |
Correct |
13 ms |
16000 KB |
Output is correct |
40 |
Correct |
13 ms |
16000 KB |
Output is correct |
41 |
Correct |
12 ms |
16000 KB |
Output is correct |
42 |
Correct |
13 ms |
16000 KB |
Output is correct |
43 |
Correct |
13 ms |
16000 KB |
Output is correct |
44 |
Correct |
13 ms |
16000 KB |
Output is correct |
45 |
Correct |
13 ms |
16000 KB |
Output is correct |
46 |
Correct |
13 ms |
16000 KB |
Output is correct |
47 |
Correct |
13 ms |
16000 KB |
Output is correct |
48 |
Correct |
13 ms |
16000 KB |
Output is correct |
49 |
Correct |
13 ms |
16256 KB |
Output is correct |
50 |
Correct |
16 ms |
16000 KB |
Output is correct |
51 |
Correct |
13 ms |
16000 KB |
Output is correct |
52 |
Correct |
448 ms |
23928 KB |
Output is correct |
53 |
Correct |
476 ms |
36472 KB |
Output is correct |
54 |
Correct |
436 ms |
36472 KB |
Output is correct |
55 |
Correct |
460 ms |
36472 KB |
Output is correct |
56 |
Correct |
448 ms |
36472 KB |
Output is correct |
57 |
Correct |
445 ms |
36600 KB |
Output is correct |
58 |
Correct |
440 ms |
36472 KB |
Output is correct |
59 |
Correct |
445 ms |
36472 KB |
Output is correct |
60 |
Correct |
447 ms |
36472 KB |
Output is correct |
61 |
Correct |
449 ms |
36344 KB |
Output is correct |
62 |
Correct |
455 ms |
36472 KB |
Output is correct |
63 |
Correct |
429 ms |
36464 KB |
Output is correct |
64 |
Correct |
440 ms |
36600 KB |
Output is correct |
65 |
Correct |
436 ms |
36472 KB |
Output is correct |
66 |
Correct |
438 ms |
36476 KB |
Output is correct |
67 |
Correct |
430 ms |
36600 KB |
Output is correct |
68 |
Correct |
428 ms |
36472 KB |
Output is correct |