#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define llinf 987654321987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
struct SEGMENT_TREE {
struct NODE {
int st, fin;
LL maxx;
} tree[3000000];
int x=0;
void maketree(int point, int num) {
if(num==1) {
x++;
tree[point].st=tree[point].fin=x;
}
if(num<=1)return;
maketree(point*2, num-num/2);
maketree(point*2+1, num/2);
tree[point].st=tree[point*2].st;
tree[point].fin=tree[point*2+1].fin;
}
LL maxrange(int a, int b, int point) {
if(tree[point].st>=a&&tree[point].fin<=b)return tree[point].maxx;
if(tree[point].st>b||tree[point].fin<a)return -llinf;
return max(maxrange(a, b, point*2), maxrange(a, b, point*2+1));
}
void updaterange(int point, int num, LL p) {
if(tree[point].st==tree[point].fin) {
tree[point].maxx=p;
return;
}
if(num<=tree[point*2].fin)updaterange(point*2, num, p);
else updaterange(point*2+1, num, p);
tree[point].maxx=max(tree[point*2].maxx, tree[point*2+1].maxx);
}
void init(int n) {
maketree(1, n);
}
LL get_max(int a, int b) {
return maxrange(a, b, 1);
}
void update(int a, LL num) {
updaterange(1, a, num);
}
}seg;
int n;
pll arr[500010];
LL sum[500010], ans;
int main()
{
scanf("%d", &n);
seg.init(n);
for(int i=1; i<=n; i++){
scanf("%lld %lld", &arr[i].F, &arr[i].S);
}
sort(arr+1, arr+n+1);
for(int i=1; i<=n; i++)
sum[i]=sum[i-1]+arr[i].S;
for(int i=1; i<=n; i++)
seg.update(i, sum[i]-arr[i].F);
for(int i=1; i<=n; i++)
ans=max(ans, seg.get_max(i, n)+arr[i].F-sum[i-1]);
printf("%lld", ans);
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
art.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &arr[i].F, &arr[i].S);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
760 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
5 ms |
760 KB |
Output is correct |
30 |
Correct |
5 ms |
760 KB |
Output is correct |
31 |
Correct |
6 ms |
888 KB |
Output is correct |
32 |
Correct |
6 ms |
760 KB |
Output is correct |
33 |
Correct |
6 ms |
888 KB |
Output is correct |
34 |
Correct |
5 ms |
760 KB |
Output is correct |
35 |
Correct |
5 ms |
888 KB |
Output is correct |
36 |
Correct |
6 ms |
888 KB |
Output is correct |
37 |
Correct |
6 ms |
760 KB |
Output is correct |
38 |
Correct |
5 ms |
760 KB |
Output is correct |
39 |
Correct |
5 ms |
760 KB |
Output is correct |
40 |
Correct |
5 ms |
756 KB |
Output is correct |
41 |
Correct |
5 ms |
756 KB |
Output is correct |
42 |
Correct |
5 ms |
760 KB |
Output is correct |
43 |
Correct |
5 ms |
888 KB |
Output is correct |
44 |
Correct |
6 ms |
888 KB |
Output is correct |
45 |
Correct |
5 ms |
760 KB |
Output is correct |
46 |
Correct |
6 ms |
760 KB |
Output is correct |
47 |
Correct |
5 ms |
888 KB |
Output is correct |
48 |
Correct |
5 ms |
760 KB |
Output is correct |
49 |
Correct |
5 ms |
888 KB |
Output is correct |
50 |
Correct |
6 ms |
760 KB |
Output is correct |
51 |
Correct |
6 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
760 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
5 ms |
760 KB |
Output is correct |
30 |
Correct |
5 ms |
760 KB |
Output is correct |
31 |
Correct |
6 ms |
888 KB |
Output is correct |
32 |
Correct |
6 ms |
760 KB |
Output is correct |
33 |
Correct |
6 ms |
888 KB |
Output is correct |
34 |
Correct |
5 ms |
760 KB |
Output is correct |
35 |
Correct |
5 ms |
888 KB |
Output is correct |
36 |
Correct |
6 ms |
888 KB |
Output is correct |
37 |
Correct |
6 ms |
760 KB |
Output is correct |
38 |
Correct |
5 ms |
760 KB |
Output is correct |
39 |
Correct |
5 ms |
760 KB |
Output is correct |
40 |
Correct |
5 ms |
756 KB |
Output is correct |
41 |
Correct |
5 ms |
756 KB |
Output is correct |
42 |
Correct |
5 ms |
760 KB |
Output is correct |
43 |
Correct |
5 ms |
888 KB |
Output is correct |
44 |
Correct |
6 ms |
888 KB |
Output is correct |
45 |
Correct |
5 ms |
760 KB |
Output is correct |
46 |
Correct |
6 ms |
760 KB |
Output is correct |
47 |
Correct |
5 ms |
888 KB |
Output is correct |
48 |
Correct |
5 ms |
760 KB |
Output is correct |
49 |
Correct |
5 ms |
888 KB |
Output is correct |
50 |
Correct |
6 ms |
760 KB |
Output is correct |
51 |
Correct |
6 ms |
760 KB |
Output is correct |
52 |
Correct |
376 ms |
41108 KB |
Output is correct |
53 |
Correct |
375 ms |
41168 KB |
Output is correct |
54 |
Correct |
372 ms |
41208 KB |
Output is correct |
55 |
Correct |
375 ms |
41200 KB |
Output is correct |
56 |
Correct |
372 ms |
41180 KB |
Output is correct |
57 |
Correct |
396 ms |
41292 KB |
Output is correct |
58 |
Correct |
372 ms |
41208 KB |
Output is correct |
59 |
Correct |
371 ms |
41080 KB |
Output is correct |
60 |
Correct |
380 ms |
41140 KB |
Output is correct |
61 |
Correct |
377 ms |
41060 KB |
Output is correct |
62 |
Correct |
395 ms |
41080 KB |
Output is correct |
63 |
Correct |
376 ms |
41136 KB |
Output is correct |
64 |
Correct |
372 ms |
41080 KB |
Output is correct |
65 |
Correct |
372 ms |
41120 KB |
Output is correct |
66 |
Correct |
380 ms |
41132 KB |
Output is correct |
67 |
Correct |
371 ms |
41052 KB |
Output is correct |
68 |
Correct |
375 ms |
41248 KB |
Output is correct |