#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<ll,ll> pii;
const int maxn = 500005;
const ll inf = 1e18 + 5;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
int n;
pii niz[maxn];
ll pref[maxn];
int main()
{
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
cin >> n;
ff(i,1,n)cin >> niz[i].fi >> niz[i].se;
sort(niz + 1, niz + n + 1);
ff(i,1,n)pref[i] = pref[i - 1] + niz[i].se;
ll rez = -inf;
ll mn = inf;
ff(i,1,n){
mn = min(mn, pref[i - 1] - niz[i].fi);
ll kol = pref[i] - niz[i].fi - mn;
rez = max(rez, kol);
}
cout << rez << endl;
return 0;
}
/**
3
2 3
11 2
4 5
// probati bojenje sahovski ili slicno
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
4 ms |
620 KB |
Output is correct |
28 |
Correct |
4 ms |
620 KB |
Output is correct |
29 |
Correct |
4 ms |
620 KB |
Output is correct |
30 |
Correct |
4 ms |
620 KB |
Output is correct |
31 |
Correct |
3 ms |
620 KB |
Output is correct |
32 |
Correct |
3 ms |
620 KB |
Output is correct |
33 |
Correct |
3 ms |
620 KB |
Output is correct |
34 |
Correct |
3 ms |
620 KB |
Output is correct |
35 |
Correct |
3 ms |
620 KB |
Output is correct |
36 |
Correct |
3 ms |
620 KB |
Output is correct |
37 |
Correct |
3 ms |
620 KB |
Output is correct |
38 |
Correct |
3 ms |
620 KB |
Output is correct |
39 |
Correct |
3 ms |
620 KB |
Output is correct |
40 |
Correct |
3 ms |
620 KB |
Output is correct |
41 |
Correct |
3 ms |
620 KB |
Output is correct |
42 |
Correct |
2 ms |
620 KB |
Output is correct |
43 |
Correct |
2 ms |
620 KB |
Output is correct |
44 |
Correct |
2 ms |
620 KB |
Output is correct |
45 |
Correct |
3 ms |
620 KB |
Output is correct |
46 |
Correct |
3 ms |
620 KB |
Output is correct |
47 |
Correct |
3 ms |
620 KB |
Output is correct |
48 |
Correct |
3 ms |
620 KB |
Output is correct |
49 |
Correct |
3 ms |
620 KB |
Output is correct |
50 |
Correct |
3 ms |
620 KB |
Output is correct |
51 |
Correct |
3 ms |
652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
4 ms |
620 KB |
Output is correct |
28 |
Correct |
4 ms |
620 KB |
Output is correct |
29 |
Correct |
4 ms |
620 KB |
Output is correct |
30 |
Correct |
4 ms |
620 KB |
Output is correct |
31 |
Correct |
3 ms |
620 KB |
Output is correct |
32 |
Correct |
3 ms |
620 KB |
Output is correct |
33 |
Correct |
3 ms |
620 KB |
Output is correct |
34 |
Correct |
3 ms |
620 KB |
Output is correct |
35 |
Correct |
3 ms |
620 KB |
Output is correct |
36 |
Correct |
3 ms |
620 KB |
Output is correct |
37 |
Correct |
3 ms |
620 KB |
Output is correct |
38 |
Correct |
3 ms |
620 KB |
Output is correct |
39 |
Correct |
3 ms |
620 KB |
Output is correct |
40 |
Correct |
3 ms |
620 KB |
Output is correct |
41 |
Correct |
3 ms |
620 KB |
Output is correct |
42 |
Correct |
2 ms |
620 KB |
Output is correct |
43 |
Correct |
2 ms |
620 KB |
Output is correct |
44 |
Correct |
2 ms |
620 KB |
Output is correct |
45 |
Correct |
3 ms |
620 KB |
Output is correct |
46 |
Correct |
3 ms |
620 KB |
Output is correct |
47 |
Correct |
3 ms |
620 KB |
Output is correct |
48 |
Correct |
3 ms |
620 KB |
Output is correct |
49 |
Correct |
3 ms |
620 KB |
Output is correct |
50 |
Correct |
3 ms |
620 KB |
Output is correct |
51 |
Correct |
3 ms |
652 KB |
Output is correct |
52 |
Correct |
201 ms |
24812 KB |
Output is correct |
53 |
Correct |
212 ms |
24816 KB |
Output is correct |
54 |
Correct |
200 ms |
24684 KB |
Output is correct |
55 |
Correct |
207 ms |
24748 KB |
Output is correct |
56 |
Correct |
228 ms |
24672 KB |
Output is correct |
57 |
Correct |
205 ms |
24812 KB |
Output is correct |
58 |
Correct |
207 ms |
24684 KB |
Output is correct |
59 |
Correct |
207 ms |
24812 KB |
Output is correct |
60 |
Correct |
201 ms |
24812 KB |
Output is correct |
61 |
Correct |
202 ms |
24684 KB |
Output is correct |
62 |
Correct |
231 ms |
24812 KB |
Output is correct |
63 |
Correct |
203 ms |
24684 KB |
Output is correct |
64 |
Correct |
204 ms |
24828 KB |
Output is correct |
65 |
Correct |
202 ms |
24812 KB |
Output is correct |
66 |
Correct |
203 ms |
24684 KB |
Output is correct |
67 |
Correct |
201 ms |
24812 KB |
Output is correct |
68 |
Correct |
204 ms |
24812 KB |
Output is correct |