/*
:---:--:--::::::--:-:----:
::-:::. ::-:::
.* -===.. :---
.-+*##=-------====-: :--:
:+##=.* -= :=+- .-=:
.+++-. :- -=. .=+- .--.
.++=- + -= :*- :-.
+*+- :- -=. -*: :=:
#*: * -=. +- .=
=:%+ -: -=. +- --
-%: * -=. *: +.
:%-.. =. -=. # -:
:=# .. + -=. == -=
---+ . = -=. .# .+
-: == . = :------::------:.-=. % .=
:- == .=. ---:. :--#+. .% :-
= .* .+.. :=- :++ -+ =:
+ #. + -=: :*%-*: *
:= :# :=:= . :-----: =+-+ .+
* -* *=- . .- :::::::. :* .#+. +
:- -+ :#. --::-----: :* ++= .-
+ :*. *. .:::::*%: ++ +.-=. +
+ -#**----: .= -*. + -= =
* +.#=+: + . .=+: =. -=. =
= -+ :++: + .. .=+= .= -=. -
= %- :====-:. =. .:--===- * -=. -
+ +-- .:--==#==-:.= + -=. =
* + * =. : .= -=. =
+ = * + = -=. +
:- = .= =: = -=. .-
* + =: * * -=. +
:- .+ =- :- .+ -=. .+
* * := * := -= *
= :- =: .- .=: -=. =:
-: * .=- + .=- -= :-
=: -: --: :- :--: -=. .=
=:+ ----. * :---. -= .+
--=*----------------------=*+=--=+--=+*+------------------------------------------------%+:.
:: := +:- -- :.
.=. =.
-= -=
.=: .=.
.=: .+:
:-- :-:
-- -=.
:--. --:
:--: .--:
.-:-: ::--.
:----. .:----
.:::::::::-::::::--::::::::.
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cerr << #x << " is " << x << "\n"
#define hehe ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repb(i, a, b) for (int i = b; i >= a; i--)
#define pii pair<int, int>
#define linebreak cout << "---------------------------------------------------------\n"
#define f first
#define s second
#define pb push_back
// good luck
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const int MS = 5e5+5, mod = 1e9+7;
int n, pref[MS];
pii p[MS];
int32_t main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> p[i].f >> p[i].s;
sort(p+1, p+n+1);
pref[0] = 0;
for (int i = 1; i <= n; i++) pref[i] = pref[i-1]+p[i].s;
int ans = -3e18, macs = -3e18;
for (int i = 1; i <= n; i++) {
macs = max(macs, p[i].f-pref[i-1]);
ans = max(ans, pref[i]-p[i].f+macs);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
396 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
396 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
396 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
604 KB |
Output is correct |
28 |
Correct |
4 ms |
604 KB |
Output is correct |
29 |
Correct |
3 ms |
648 KB |
Output is correct |
30 |
Correct |
4 ms |
604 KB |
Output is correct |
31 |
Correct |
4 ms |
604 KB |
Output is correct |
32 |
Correct |
4 ms |
604 KB |
Output is correct |
33 |
Correct |
4 ms |
500 KB |
Output is correct |
34 |
Correct |
4 ms |
604 KB |
Output is correct |
35 |
Correct |
4 ms |
600 KB |
Output is correct |
36 |
Correct |
3 ms |
604 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
4 ms |
604 KB |
Output is correct |
39 |
Correct |
4 ms |
604 KB |
Output is correct |
40 |
Correct |
4 ms |
604 KB |
Output is correct |
41 |
Correct |
5 ms |
604 KB |
Output is correct |
42 |
Correct |
4 ms |
456 KB |
Output is correct |
43 |
Correct |
5 ms |
604 KB |
Output is correct |
44 |
Correct |
4 ms |
604 KB |
Output is correct |
45 |
Correct |
5 ms |
604 KB |
Output is correct |
46 |
Correct |
4 ms |
604 KB |
Output is correct |
47 |
Correct |
4 ms |
556 KB |
Output is correct |
48 |
Correct |
3 ms |
572 KB |
Output is correct |
49 |
Correct |
3 ms |
604 KB |
Output is correct |
50 |
Correct |
4 ms |
604 KB |
Output is correct |
51 |
Correct |
4 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
396 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
604 KB |
Output is correct |
28 |
Correct |
4 ms |
604 KB |
Output is correct |
29 |
Correct |
3 ms |
648 KB |
Output is correct |
30 |
Correct |
4 ms |
604 KB |
Output is correct |
31 |
Correct |
4 ms |
604 KB |
Output is correct |
32 |
Correct |
4 ms |
604 KB |
Output is correct |
33 |
Correct |
4 ms |
500 KB |
Output is correct |
34 |
Correct |
4 ms |
604 KB |
Output is correct |
35 |
Correct |
4 ms |
600 KB |
Output is correct |
36 |
Correct |
3 ms |
604 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
4 ms |
604 KB |
Output is correct |
39 |
Correct |
4 ms |
604 KB |
Output is correct |
40 |
Correct |
4 ms |
604 KB |
Output is correct |
41 |
Correct |
5 ms |
604 KB |
Output is correct |
42 |
Correct |
4 ms |
456 KB |
Output is correct |
43 |
Correct |
5 ms |
604 KB |
Output is correct |
44 |
Correct |
4 ms |
604 KB |
Output is correct |
45 |
Correct |
5 ms |
604 KB |
Output is correct |
46 |
Correct |
4 ms |
604 KB |
Output is correct |
47 |
Correct |
4 ms |
556 KB |
Output is correct |
48 |
Correct |
3 ms |
572 KB |
Output is correct |
49 |
Correct |
3 ms |
604 KB |
Output is correct |
50 |
Correct |
4 ms |
604 KB |
Output is correct |
51 |
Correct |
4 ms |
600 KB |
Output is correct |
52 |
Correct |
342 ms |
24512 KB |
Output is correct |
53 |
Correct |
331 ms |
24756 KB |
Output is correct |
54 |
Correct |
328 ms |
24564 KB |
Output is correct |
55 |
Correct |
336 ms |
24660 KB |
Output is correct |
56 |
Correct |
341 ms |
24660 KB |
Output is correct |
57 |
Correct |
338 ms |
24656 KB |
Output is correct |
58 |
Correct |
327 ms |
24668 KB |
Output is correct |
59 |
Correct |
337 ms |
24736 KB |
Output is correct |
60 |
Correct |
327 ms |
24656 KB |
Output is correct |
61 |
Correct |
331 ms |
24656 KB |
Output is correct |
62 |
Correct |
327 ms |
24724 KB |
Output is correct |
63 |
Correct |
330 ms |
24788 KB |
Output is correct |
64 |
Correct |
333 ms |
24676 KB |
Output is correct |
65 |
Correct |
341 ms |
24820 KB |
Output is correct |
66 |
Correct |
327 ms |
24808 KB |
Output is correct |
67 |
Correct |
332 ms |
24660 KB |
Output is correct |
68 |
Correct |
329 ms |
24660 KB |
Output is correct |