#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector<pair<ll,int> > arr(N);
for(int i=0;i<N;i++){
cin >> arr[i].first >> arr[i].second;
}
sort(arr.begin(),arr.end());
multiset<ll> mt;
ll sum = 0;
for(int i=0;i<N;i++){
sum += arr[i].second;
mt.insert(sum-arr[i].first);
}
sum = 0;
ll res = 0;
for(int i=0;i<N;i++){
ll last = *prev(mt.end());
res = max(res,last-sum+arr[i].first);
sum += arr[i].second;
mt.erase(mt.find(sum-arr[i].first));
}
cout << res << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
3 ms |
716 KB |
Output is correct |
28 |
Correct |
3 ms |
708 KB |
Output is correct |
29 |
Correct |
3 ms |
716 KB |
Output is correct |
30 |
Correct |
3 ms |
712 KB |
Output is correct |
31 |
Correct |
4 ms |
704 KB |
Output is correct |
32 |
Correct |
3 ms |
708 KB |
Output is correct |
33 |
Correct |
3 ms |
696 KB |
Output is correct |
34 |
Correct |
3 ms |
716 KB |
Output is correct |
35 |
Correct |
3 ms |
752 KB |
Output is correct |
36 |
Correct |
3 ms |
640 KB |
Output is correct |
37 |
Correct |
3 ms |
708 KB |
Output is correct |
38 |
Correct |
3 ms |
628 KB |
Output is correct |
39 |
Correct |
3 ms |
708 KB |
Output is correct |
40 |
Correct |
3 ms |
716 KB |
Output is correct |
41 |
Correct |
3 ms |
716 KB |
Output is correct |
42 |
Correct |
3 ms |
716 KB |
Output is correct |
43 |
Correct |
3 ms |
716 KB |
Output is correct |
44 |
Correct |
3 ms |
708 KB |
Output is correct |
45 |
Correct |
3 ms |
644 KB |
Output is correct |
46 |
Correct |
3 ms |
648 KB |
Output is correct |
47 |
Correct |
3 ms |
700 KB |
Output is correct |
48 |
Correct |
3 ms |
708 KB |
Output is correct |
49 |
Correct |
3 ms |
620 KB |
Output is correct |
50 |
Correct |
3 ms |
704 KB |
Output is correct |
51 |
Correct |
3 ms |
704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
3 ms |
716 KB |
Output is correct |
28 |
Correct |
3 ms |
708 KB |
Output is correct |
29 |
Correct |
3 ms |
716 KB |
Output is correct |
30 |
Correct |
3 ms |
712 KB |
Output is correct |
31 |
Correct |
4 ms |
704 KB |
Output is correct |
32 |
Correct |
3 ms |
708 KB |
Output is correct |
33 |
Correct |
3 ms |
696 KB |
Output is correct |
34 |
Correct |
3 ms |
716 KB |
Output is correct |
35 |
Correct |
3 ms |
752 KB |
Output is correct |
36 |
Correct |
3 ms |
640 KB |
Output is correct |
37 |
Correct |
3 ms |
708 KB |
Output is correct |
38 |
Correct |
3 ms |
628 KB |
Output is correct |
39 |
Correct |
3 ms |
708 KB |
Output is correct |
40 |
Correct |
3 ms |
716 KB |
Output is correct |
41 |
Correct |
3 ms |
716 KB |
Output is correct |
42 |
Correct |
3 ms |
716 KB |
Output is correct |
43 |
Correct |
3 ms |
716 KB |
Output is correct |
44 |
Correct |
3 ms |
708 KB |
Output is correct |
45 |
Correct |
3 ms |
644 KB |
Output is correct |
46 |
Correct |
3 ms |
648 KB |
Output is correct |
47 |
Correct |
3 ms |
700 KB |
Output is correct |
48 |
Correct |
3 ms |
708 KB |
Output is correct |
49 |
Correct |
3 ms |
620 KB |
Output is correct |
50 |
Correct |
3 ms |
704 KB |
Output is correct |
51 |
Correct |
3 ms |
704 KB |
Output is correct |
52 |
Correct |
256 ms |
44216 KB |
Output is correct |
53 |
Correct |
277 ms |
44200 KB |
Output is correct |
54 |
Correct |
274 ms |
44332 KB |
Output is correct |
55 |
Correct |
285 ms |
44216 KB |
Output is correct |
56 |
Correct |
311 ms |
44204 KB |
Output is correct |
57 |
Correct |
333 ms |
44216 KB |
Output is correct |
58 |
Correct |
300 ms |
44228 KB |
Output is correct |
59 |
Correct |
289 ms |
44200 KB |
Output is correct |
60 |
Correct |
288 ms |
44220 KB |
Output is correct |
61 |
Correct |
280 ms |
44100 KB |
Output is correct |
62 |
Correct |
276 ms |
44212 KB |
Output is correct |
63 |
Correct |
277 ms |
44216 KB |
Output is correct |
64 |
Correct |
283 ms |
44212 KB |
Output is correct |
65 |
Correct |
266 ms |
44256 KB |
Output is correct |
66 |
Correct |
255 ms |
44216 KB |
Output is correct |
67 |
Correct |
269 ms |
44228 KB |
Output is correct |
68 |
Correct |
332 ms |
44164 KB |
Output is correct |