#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin >> n;
map<int,int> mp;
for (int i = 0; i<n; i++){
int a,b;
cin >> a >> b;
mp[a] += b;
}
vector<pair<int,int>> vec;
for (auto u : mp){
vec.push_back(u);
}
sort(vec.begin(),vec.end());
int sz = vec.size();
int pf[sz+1];
pf[0] = 0;
multiset<int> ms;
for (int i = 1; i<=sz; i++){
pf[i] = pf[i-1] + vec[i-1].second;
ms.insert(pf[i]-vec[i-1].first);
}
//set of pf[i] - vec[i-1].first
//get max of that
int bst = 0;
for (int i = 1; i<=sz; i++){
//start from i
int cr = vec[i-1].first - pf[i-1];
auto it = ms.rbegin();
int val = *it;
bst = max(bst, cr + val);
ms.erase(ms.find(pf[i]-vec[i-1].first));
}
cout << bst;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
448 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
436 KB |
Output is correct |
18 |
Correct |
1 ms |
360 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
440 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
448 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
436 KB |
Output is correct |
18 |
Correct |
1 ms |
360 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
440 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
6 ms |
1116 KB |
Output is correct |
28 |
Correct |
5 ms |
1112 KB |
Output is correct |
29 |
Correct |
5 ms |
1116 KB |
Output is correct |
30 |
Correct |
9 ms |
1412 KB |
Output is correct |
31 |
Correct |
6 ms |
1116 KB |
Output is correct |
32 |
Correct |
6 ms |
1116 KB |
Output is correct |
33 |
Correct |
6 ms |
1008 KB |
Output is correct |
34 |
Correct |
6 ms |
1116 KB |
Output is correct |
35 |
Correct |
8 ms |
1116 KB |
Output is correct |
36 |
Correct |
6 ms |
1116 KB |
Output is correct |
37 |
Correct |
6 ms |
1116 KB |
Output is correct |
38 |
Correct |
6 ms |
1156 KB |
Output is correct |
39 |
Correct |
6 ms |
1116 KB |
Output is correct |
40 |
Correct |
6 ms |
1116 KB |
Output is correct |
41 |
Correct |
7 ms |
1116 KB |
Output is correct |
42 |
Correct |
6 ms |
1116 KB |
Output is correct |
43 |
Correct |
8 ms |
1112 KB |
Output is correct |
44 |
Correct |
7 ms |
1092 KB |
Output is correct |
45 |
Correct |
6 ms |
1116 KB |
Output is correct |
46 |
Correct |
6 ms |
1032 KB |
Output is correct |
47 |
Correct |
6 ms |
1116 KB |
Output is correct |
48 |
Correct |
5 ms |
1168 KB |
Output is correct |
49 |
Correct |
5 ms |
1116 KB |
Output is correct |
50 |
Correct |
6 ms |
1116 KB |
Output is correct |
51 |
Correct |
6 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
448 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
436 KB |
Output is correct |
18 |
Correct |
1 ms |
360 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
440 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
6 ms |
1116 KB |
Output is correct |
28 |
Correct |
5 ms |
1112 KB |
Output is correct |
29 |
Correct |
5 ms |
1116 KB |
Output is correct |
30 |
Correct |
9 ms |
1412 KB |
Output is correct |
31 |
Correct |
6 ms |
1116 KB |
Output is correct |
32 |
Correct |
6 ms |
1116 KB |
Output is correct |
33 |
Correct |
6 ms |
1008 KB |
Output is correct |
34 |
Correct |
6 ms |
1116 KB |
Output is correct |
35 |
Correct |
8 ms |
1116 KB |
Output is correct |
36 |
Correct |
6 ms |
1116 KB |
Output is correct |
37 |
Correct |
6 ms |
1116 KB |
Output is correct |
38 |
Correct |
6 ms |
1156 KB |
Output is correct |
39 |
Correct |
6 ms |
1116 KB |
Output is correct |
40 |
Correct |
6 ms |
1116 KB |
Output is correct |
41 |
Correct |
7 ms |
1116 KB |
Output is correct |
42 |
Correct |
6 ms |
1116 KB |
Output is correct |
43 |
Correct |
8 ms |
1112 KB |
Output is correct |
44 |
Correct |
7 ms |
1092 KB |
Output is correct |
45 |
Correct |
6 ms |
1116 KB |
Output is correct |
46 |
Correct |
6 ms |
1032 KB |
Output is correct |
47 |
Correct |
6 ms |
1116 KB |
Output is correct |
48 |
Correct |
5 ms |
1168 KB |
Output is correct |
49 |
Correct |
5 ms |
1116 KB |
Output is correct |
50 |
Correct |
6 ms |
1116 KB |
Output is correct |
51 |
Correct |
6 ms |
1116 KB |
Output is correct |
52 |
Correct |
873 ms |
79608 KB |
Output is correct |
53 |
Correct |
820 ms |
79724 KB |
Output is correct |
54 |
Correct |
842 ms |
80000 KB |
Output is correct |
55 |
Correct |
869 ms |
79572 KB |
Output is correct |
56 |
Correct |
886 ms |
79904 KB |
Output is correct |
57 |
Correct |
853 ms |
79664 KB |
Output is correct |
58 |
Correct |
853 ms |
79672 KB |
Output is correct |
59 |
Correct |
861 ms |
79628 KB |
Output is correct |
60 |
Correct |
841 ms |
79528 KB |
Output is correct |
61 |
Correct |
955 ms |
79420 KB |
Output is correct |
62 |
Correct |
912 ms |
79528 KB |
Output is correct |
63 |
Correct |
857 ms |
79436 KB |
Output is correct |
64 |
Correct |
888 ms |
79528 KB |
Output is correct |
65 |
Correct |
841 ms |
79588 KB |
Output is correct |
66 |
Correct |
873 ms |
79644 KB |
Output is correct |
67 |
Correct |
858 ms |
79484 KB |
Output is correct |
68 |
Correct |
869 ms |
79472 KB |
Output is correct |