#include <bits/stdc++.h>
#define DIM 500010
#define INF 2000000000000000000LL
using namespace std;
struct idk{
long long a,b;
} v[DIM];
long long aint[DIM*4],sp[DIM],sol;
int n,i;
inline int cmp (idk a, idk b){
return a.a < b.a;
}
void build (int nod, int st, int dr){
if (st == dr){
aint[nod] = sp[st] - v[st].a;
return;
}
int mid = (st+dr)>>1;
build (nod<<1,st,mid);
build ((nod<<1)|1,mid+1,dr);
aint[nod] = max (aint[nod<<1],aint[(nod<<1)|1]);
}
long long query (int nod, int st, int dr, int x, int y){
if (x <= st && dr <= y)
return aint[nod];
int mid = (st+dr)>>1;
long long sol_st = -INF, sol_dr = -INF;
if (x <= mid)
sol_st = query (nod<<1,st,mid,x,y);
if (y > mid)
sol_dr = query ((nod<<1)|1,mid+1,dr,x,y);
return max (sol_st,sol_dr);
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n;
sol = -INF;
for (i=1;i<=n;i++){
cin>>v[i].a>>v[i].b;
sol = max (sol,v[i].b);
}
sort (v+1,v+n+1,cmp);
for (i=1;i<=n;i++)
sp[i] = sp[i-1] + v[i].b;
build (1,1,n);
for (i=1;i<n;i++)
sol = max (sol,v[i].a - sp[i-1] + query(1,1,n,i+1,n));
cout<<sol;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 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 |
6 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 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 |
6 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 |
13 ms |
768 KB |
Output is correct |
28 |
Correct |
13 ms |
768 KB |
Output is correct |
29 |
Correct |
13 ms |
768 KB |
Output is correct |
30 |
Correct |
13 ms |
768 KB |
Output is correct |
31 |
Correct |
13 ms |
640 KB |
Output is correct |
32 |
Correct |
13 ms |
768 KB |
Output is correct |
33 |
Correct |
13 ms |
768 KB |
Output is correct |
34 |
Correct |
13 ms |
768 KB |
Output is correct |
35 |
Correct |
13 ms |
768 KB |
Output is correct |
36 |
Correct |
13 ms |
768 KB |
Output is correct |
37 |
Correct |
13 ms |
672 KB |
Output is correct |
38 |
Correct |
13 ms |
768 KB |
Output is correct |
39 |
Correct |
13 ms |
768 KB |
Output is correct |
40 |
Correct |
13 ms |
768 KB |
Output is correct |
41 |
Correct |
13 ms |
640 KB |
Output is correct |
42 |
Correct |
14 ms |
640 KB |
Output is correct |
43 |
Correct |
13 ms |
768 KB |
Output is correct |
44 |
Correct |
13 ms |
768 KB |
Output is correct |
45 |
Correct |
14 ms |
768 KB |
Output is correct |
46 |
Correct |
13 ms |
768 KB |
Output is correct |
47 |
Correct |
13 ms |
768 KB |
Output is correct |
48 |
Correct |
13 ms |
768 KB |
Output is correct |
49 |
Correct |
13 ms |
768 KB |
Output is correct |
50 |
Correct |
13 ms |
768 KB |
Output is correct |
51 |
Correct |
13 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 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 |
6 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 |
13 ms |
768 KB |
Output is correct |
28 |
Correct |
13 ms |
768 KB |
Output is correct |
29 |
Correct |
13 ms |
768 KB |
Output is correct |
30 |
Correct |
13 ms |
768 KB |
Output is correct |
31 |
Correct |
13 ms |
640 KB |
Output is correct |
32 |
Correct |
13 ms |
768 KB |
Output is correct |
33 |
Correct |
13 ms |
768 KB |
Output is correct |
34 |
Correct |
13 ms |
768 KB |
Output is correct |
35 |
Correct |
13 ms |
768 KB |
Output is correct |
36 |
Correct |
13 ms |
768 KB |
Output is correct |
37 |
Correct |
13 ms |
672 KB |
Output is correct |
38 |
Correct |
13 ms |
768 KB |
Output is correct |
39 |
Correct |
13 ms |
768 KB |
Output is correct |
40 |
Correct |
13 ms |
768 KB |
Output is correct |
41 |
Correct |
13 ms |
640 KB |
Output is correct |
42 |
Correct |
14 ms |
640 KB |
Output is correct |
43 |
Correct |
13 ms |
768 KB |
Output is correct |
44 |
Correct |
13 ms |
768 KB |
Output is correct |
45 |
Correct |
14 ms |
768 KB |
Output is correct |
46 |
Correct |
13 ms |
768 KB |
Output is correct |
47 |
Correct |
13 ms |
768 KB |
Output is correct |
48 |
Correct |
13 ms |
768 KB |
Output is correct |
49 |
Correct |
13 ms |
768 KB |
Output is correct |
50 |
Correct |
13 ms |
768 KB |
Output is correct |
51 |
Correct |
13 ms |
768 KB |
Output is correct |
52 |
Correct |
866 ms |
33020 KB |
Output is correct |
53 |
Correct |
877 ms |
32888 KB |
Output is correct |
54 |
Correct |
882 ms |
33188 KB |
Output is correct |
55 |
Correct |
868 ms |
33144 KB |
Output is correct |
56 |
Correct |
876 ms |
32988 KB |
Output is correct |
57 |
Correct |
878 ms |
32980 KB |
Output is correct |
58 |
Correct |
907 ms |
32892 KB |
Output is correct |
59 |
Correct |
880 ms |
33052 KB |
Output is correct |
60 |
Correct |
871 ms |
33016 KB |
Output is correct |
61 |
Correct |
857 ms |
32888 KB |
Output is correct |
62 |
Correct |
873 ms |
33000 KB |
Output is correct |
63 |
Correct |
877 ms |
33016 KB |
Output is correct |
64 |
Correct |
871 ms |
32888 KB |
Output is correct |
65 |
Correct |
873 ms |
33004 KB |
Output is correct |
66 |
Correct |
866 ms |
33016 KB |
Output is correct |
67 |
Correct |
873 ms |
33060 KB |
Output is correct |
68 |
Correct |
875 ms |
33016 KB |
Output is correct |