#include <bits/stdc++.h>
#define F first
#define S second
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
using namespace std;
#define int ll
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
const int N = 5e5 + 11;
const ll INF2 = 2e18 + 11;
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
int n,t[N*4],pref[N];
pii a[N];
void upd(int v, int l, int r, int pos, int val) {
if (l == r) {
t[v]=val;
return;
}
int md=l+((r - l) >> 1ll);
if (pos <= md) upd(v+v,l,md,pos,val);
else upd(v+v+1,md+1,r,pos,val);
t[v]=max(t[v+v],t[v+v+1]);
}
int get(int v, int l, int r, int left, int right) {
if (left > r || right < l) return 0;
if (left <= l and r <= right) return t[v];
int md=l+((r-l)>>1ll);
return max(get(v+v,l,md,left,right),get(v+v+1,md+1,r,left,right));
}
main() {
cin>>n;
fo(i,1,n,1) cin>>a[i].F>>a[i].S;
sort(a+1,a+n+1, greater<pii>());
fo(i,1,n,1) pref[i]=pref[i-1]+a[i].S;
foo(i,n,2,1) upd(1,1,n,i,pref[i]+a[i].F);
int ans=-INF2;
fo(l,1,n,1) chmax(ans,get(1,1,n,l,n)-pref[l-1]-a[l].F);
cout<<ans;
return 0;
}
Compilation message
art.cpp:42:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
380 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
380 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
15 ms |
632 KB |
Output is correct |
28 |
Correct |
14 ms |
632 KB |
Output is correct |
29 |
Correct |
14 ms |
632 KB |
Output is correct |
30 |
Correct |
13 ms |
632 KB |
Output is correct |
31 |
Correct |
14 ms |
632 KB |
Output is correct |
32 |
Correct |
14 ms |
632 KB |
Output is correct |
33 |
Correct |
14 ms |
632 KB |
Output is correct |
34 |
Correct |
14 ms |
632 KB |
Output is correct |
35 |
Correct |
13 ms |
632 KB |
Output is correct |
36 |
Correct |
14 ms |
632 KB |
Output is correct |
37 |
Correct |
14 ms |
632 KB |
Output is correct |
38 |
Correct |
14 ms |
632 KB |
Output is correct |
39 |
Correct |
14 ms |
632 KB |
Output is correct |
40 |
Correct |
15 ms |
632 KB |
Output is correct |
41 |
Correct |
13 ms |
632 KB |
Output is correct |
42 |
Correct |
13 ms |
632 KB |
Output is correct |
43 |
Correct |
14 ms |
632 KB |
Output is correct |
44 |
Correct |
14 ms |
632 KB |
Output is correct |
45 |
Correct |
14 ms |
632 KB |
Output is correct |
46 |
Correct |
14 ms |
504 KB |
Output is correct |
47 |
Correct |
14 ms |
632 KB |
Output is correct |
48 |
Correct |
13 ms |
632 KB |
Output is correct |
49 |
Correct |
13 ms |
632 KB |
Output is correct |
50 |
Correct |
14 ms |
632 KB |
Output is correct |
51 |
Correct |
13 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
380 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
15 ms |
632 KB |
Output is correct |
28 |
Correct |
14 ms |
632 KB |
Output is correct |
29 |
Correct |
14 ms |
632 KB |
Output is correct |
30 |
Correct |
13 ms |
632 KB |
Output is correct |
31 |
Correct |
14 ms |
632 KB |
Output is correct |
32 |
Correct |
14 ms |
632 KB |
Output is correct |
33 |
Correct |
14 ms |
632 KB |
Output is correct |
34 |
Correct |
14 ms |
632 KB |
Output is correct |
35 |
Correct |
13 ms |
632 KB |
Output is correct |
36 |
Correct |
14 ms |
632 KB |
Output is correct |
37 |
Correct |
14 ms |
632 KB |
Output is correct |
38 |
Correct |
14 ms |
632 KB |
Output is correct |
39 |
Correct |
14 ms |
632 KB |
Output is correct |
40 |
Correct |
15 ms |
632 KB |
Output is correct |
41 |
Correct |
13 ms |
632 KB |
Output is correct |
42 |
Correct |
13 ms |
632 KB |
Output is correct |
43 |
Correct |
14 ms |
632 KB |
Output is correct |
44 |
Correct |
14 ms |
632 KB |
Output is correct |
45 |
Correct |
14 ms |
632 KB |
Output is correct |
46 |
Correct |
14 ms |
504 KB |
Output is correct |
47 |
Correct |
14 ms |
632 KB |
Output is correct |
48 |
Correct |
13 ms |
632 KB |
Output is correct |
49 |
Correct |
13 ms |
632 KB |
Output is correct |
50 |
Correct |
14 ms |
632 KB |
Output is correct |
51 |
Correct |
13 ms |
632 KB |
Output is correct |
52 |
Correct |
933 ms |
20436 KB |
Output is correct |
53 |
Correct |
946 ms |
33016 KB |
Output is correct |
54 |
Correct |
942 ms |
32888 KB |
Output is correct |
55 |
Correct |
952 ms |
33144 KB |
Output is correct |
56 |
Correct |
926 ms |
33016 KB |
Output is correct |
57 |
Correct |
943 ms |
33120 KB |
Output is correct |
58 |
Correct |
957 ms |
32892 KB |
Output is correct |
59 |
Correct |
946 ms |
33016 KB |
Output is correct |
60 |
Correct |
935 ms |
33016 KB |
Output is correct |
61 |
Correct |
937 ms |
33016 KB |
Output is correct |
62 |
Correct |
932 ms |
33144 KB |
Output is correct |
63 |
Correct |
954 ms |
33016 KB |
Output is correct |
64 |
Correct |
936 ms |
33016 KB |
Output is correct |
65 |
Correct |
952 ms |
32908 KB |
Output is correct |
66 |
Correct |
951 ms |
32936 KB |
Output is correct |
67 |
Correct |
960 ms |
33012 KB |
Output is correct |
68 |
Correct |
944 ms |
32928 KB |
Output is correct |