#include<bits/stdc++.h>
#define maxn 500009
using namespace std;
pair<long long,long long> a[maxn];
long long A[maxn], s[maxn], B[maxn];
main(){
long long n;
cin >> n;
for(long long i= 1; i <= n; i++)
cin >> a[i].first >> a[i].second;
sort(a + 1, a + n + 1);
for(long long i = 1; i <= n; i++){
s[i] = s[i - 1] + a[i] . second;
}
for(long long i = 1 ; i <= n; i++){
A[i] = s[i] - a[i] . first;
B[i] = -a[i] .first + s[i - 1];
}
long long MI = 1e18, ans = -1e18;
for(long long i = 1; i <= n; i++){
MI = min(MI, B[i]);
ans = max(ans, A[i] - MI);
}
cout<< ans << endl;
}
Compilation message
art.cpp:6:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
520 KB |
Output is correct |
7 |
Correct |
3 ms |
520 KB |
Output is correct |
8 |
Correct |
3 ms |
648 KB |
Output is correct |
9 |
Correct |
3 ms |
648 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
3 ms |
664 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 |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
520 KB |
Output is correct |
7 |
Correct |
3 ms |
520 KB |
Output is correct |
8 |
Correct |
3 ms |
648 KB |
Output is correct |
9 |
Correct |
3 ms |
648 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
3 ms |
664 KB |
Output is correct |
12 |
Correct |
4 ms |
664 KB |
Output is correct |
13 |
Correct |
2 ms |
664 KB |
Output is correct |
14 |
Correct |
4 ms |
664 KB |
Output is correct |
15 |
Correct |
4 ms |
664 KB |
Output is correct |
16 |
Correct |
3 ms |
664 KB |
Output is correct |
17 |
Correct |
2 ms |
664 KB |
Output is correct |
18 |
Correct |
3 ms |
664 KB |
Output is correct |
19 |
Correct |
4 ms |
664 KB |
Output is correct |
20 |
Correct |
3 ms |
664 KB |
Output is correct |
21 |
Correct |
3 ms |
664 KB |
Output is correct |
22 |
Correct |
4 ms |
712 KB |
Output is correct |
23 |
Correct |
3 ms |
712 KB |
Output is correct |
24 |
Correct |
3 ms |
712 KB |
Output is correct |
25 |
Correct |
3 ms |
712 KB |
Output is correct |
26 |
Correct |
2 ms |
712 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 |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
520 KB |
Output is correct |
7 |
Correct |
3 ms |
520 KB |
Output is correct |
8 |
Correct |
3 ms |
648 KB |
Output is correct |
9 |
Correct |
3 ms |
648 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
3 ms |
664 KB |
Output is correct |
12 |
Correct |
4 ms |
664 KB |
Output is correct |
13 |
Correct |
2 ms |
664 KB |
Output is correct |
14 |
Correct |
4 ms |
664 KB |
Output is correct |
15 |
Correct |
4 ms |
664 KB |
Output is correct |
16 |
Correct |
3 ms |
664 KB |
Output is correct |
17 |
Correct |
2 ms |
664 KB |
Output is correct |
18 |
Correct |
3 ms |
664 KB |
Output is correct |
19 |
Correct |
4 ms |
664 KB |
Output is correct |
20 |
Correct |
3 ms |
664 KB |
Output is correct |
21 |
Correct |
3 ms |
664 KB |
Output is correct |
22 |
Correct |
4 ms |
712 KB |
Output is correct |
23 |
Correct |
3 ms |
712 KB |
Output is correct |
24 |
Correct |
3 ms |
712 KB |
Output is correct |
25 |
Correct |
3 ms |
712 KB |
Output is correct |
26 |
Correct |
2 ms |
712 KB |
Output is correct |
27 |
Correct |
10 ms |
748 KB |
Output is correct |
28 |
Correct |
12 ms |
748 KB |
Output is correct |
29 |
Correct |
10 ms |
800 KB |
Output is correct |
30 |
Correct |
11 ms |
800 KB |
Output is correct |
31 |
Correct |
11 ms |
800 KB |
Output is correct |
32 |
Correct |
10 ms |
800 KB |
Output is correct |
33 |
Correct |
10 ms |
800 KB |
Output is correct |
34 |
Correct |
14 ms |
800 KB |
Output is correct |
35 |
Correct |
15 ms |
800 KB |
Output is correct |
36 |
Correct |
11 ms |
800 KB |
Output is correct |
37 |
Correct |
10 ms |
800 KB |
Output is correct |
38 |
Correct |
12 ms |
816 KB |
Output is correct |
39 |
Correct |
12 ms |
816 KB |
Output is correct |
40 |
Correct |
11 ms |
816 KB |
Output is correct |
41 |
Correct |
12 ms |
816 KB |
Output is correct |
42 |
Correct |
12 ms |
816 KB |
Output is correct |
43 |
Correct |
10 ms |
816 KB |
Output is correct |
44 |
Correct |
11 ms |
816 KB |
Output is correct |
45 |
Correct |
10 ms |
816 KB |
Output is correct |
46 |
Correct |
10 ms |
816 KB |
Output is correct |
47 |
Correct |
12 ms |
816 KB |
Output is correct |
48 |
Correct |
9 ms |
816 KB |
Output is correct |
49 |
Correct |
11 ms |
816 KB |
Output is correct |
50 |
Correct |
14 ms |
816 KB |
Output is correct |
51 |
Correct |
9 ms |
816 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 |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
520 KB |
Output is correct |
7 |
Correct |
3 ms |
520 KB |
Output is correct |
8 |
Correct |
3 ms |
648 KB |
Output is correct |
9 |
Correct |
3 ms |
648 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
3 ms |
664 KB |
Output is correct |
12 |
Correct |
4 ms |
664 KB |
Output is correct |
13 |
Correct |
2 ms |
664 KB |
Output is correct |
14 |
Correct |
4 ms |
664 KB |
Output is correct |
15 |
Correct |
4 ms |
664 KB |
Output is correct |
16 |
Correct |
3 ms |
664 KB |
Output is correct |
17 |
Correct |
2 ms |
664 KB |
Output is correct |
18 |
Correct |
3 ms |
664 KB |
Output is correct |
19 |
Correct |
4 ms |
664 KB |
Output is correct |
20 |
Correct |
3 ms |
664 KB |
Output is correct |
21 |
Correct |
3 ms |
664 KB |
Output is correct |
22 |
Correct |
4 ms |
712 KB |
Output is correct |
23 |
Correct |
3 ms |
712 KB |
Output is correct |
24 |
Correct |
3 ms |
712 KB |
Output is correct |
25 |
Correct |
3 ms |
712 KB |
Output is correct |
26 |
Correct |
2 ms |
712 KB |
Output is correct |
27 |
Correct |
10 ms |
748 KB |
Output is correct |
28 |
Correct |
12 ms |
748 KB |
Output is correct |
29 |
Correct |
10 ms |
800 KB |
Output is correct |
30 |
Correct |
11 ms |
800 KB |
Output is correct |
31 |
Correct |
11 ms |
800 KB |
Output is correct |
32 |
Correct |
10 ms |
800 KB |
Output is correct |
33 |
Correct |
10 ms |
800 KB |
Output is correct |
34 |
Correct |
14 ms |
800 KB |
Output is correct |
35 |
Correct |
15 ms |
800 KB |
Output is correct |
36 |
Correct |
11 ms |
800 KB |
Output is correct |
37 |
Correct |
10 ms |
800 KB |
Output is correct |
38 |
Correct |
12 ms |
816 KB |
Output is correct |
39 |
Correct |
12 ms |
816 KB |
Output is correct |
40 |
Correct |
11 ms |
816 KB |
Output is correct |
41 |
Correct |
12 ms |
816 KB |
Output is correct |
42 |
Correct |
12 ms |
816 KB |
Output is correct |
43 |
Correct |
10 ms |
816 KB |
Output is correct |
44 |
Correct |
11 ms |
816 KB |
Output is correct |
45 |
Correct |
10 ms |
816 KB |
Output is correct |
46 |
Correct |
10 ms |
816 KB |
Output is correct |
47 |
Correct |
12 ms |
816 KB |
Output is correct |
48 |
Correct |
9 ms |
816 KB |
Output is correct |
49 |
Correct |
11 ms |
816 KB |
Output is correct |
50 |
Correct |
14 ms |
816 KB |
Output is correct |
51 |
Correct |
9 ms |
816 KB |
Output is correct |
52 |
Correct |
789 ms |
31484 KB |
Output is correct |
53 |
Correct |
769 ms |
44256 KB |
Output is correct |
54 |
Correct |
721 ms |
56956 KB |
Output is correct |
55 |
Correct |
760 ms |
69612 KB |
Output is correct |
56 |
Correct |
814 ms |
82256 KB |
Output is correct |
57 |
Correct |
755 ms |
94948 KB |
Output is correct |
58 |
Correct |
828 ms |
107660 KB |
Output is correct |
59 |
Correct |
859 ms |
120256 KB |
Output is correct |
60 |
Correct |
735 ms |
132932 KB |
Output is correct |
61 |
Correct |
683 ms |
145592 KB |
Output is correct |
62 |
Correct |
752 ms |
158284 KB |
Output is correct |
63 |
Correct |
684 ms |
170844 KB |
Output is correct |
64 |
Correct |
739 ms |
183656 KB |
Output is correct |
65 |
Correct |
751 ms |
196200 KB |
Output is correct |
66 |
Correct |
796 ms |
208856 KB |
Output is correct |
67 |
Correct |
787 ms |
221344 KB |
Output is correct |
68 |
Correct |
716 ms |
233092 KB |
Output is correct |