#include <iostream>
#include <algorithm>
#include <numeric>
#include <map>
using namespace std;
using ll = long long;
const int MAXN = 5e5 + 5;
int n;
ll a[MAXN], b[MAXN];
ll solve() {
int p[n];
iota(p, p + n, 0);
sort(p, p + n, [](int i, int j) {
return a[i] < a[j];
});
ll pfx_sum = 0, loss = 0;
map<ll, ll> m;
ll ans = 0;
for (int i = 0; i < n; i++) {
if (i == 0 or a[p[i]] != a[p[i - 1]]) {
m[a[p[i]]] = a[p[i]] - pfx_sum;
loss = max(loss, m[a[p[i]]]);
}
pfx_sum += b[p[i]];
ans = max(ans, pfx_sum + loss - a[p[i]]);
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
cout << solve() << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
852 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
832 KB |
Output is correct |
30 |
Correct |
3 ms |
832 KB |
Output is correct |
31 |
Correct |
3 ms |
848 KB |
Output is correct |
32 |
Correct |
3 ms |
852 KB |
Output is correct |
33 |
Correct |
3 ms |
788 KB |
Output is correct |
34 |
Correct |
3 ms |
852 KB |
Output is correct |
35 |
Correct |
3 ms |
852 KB |
Output is correct |
36 |
Correct |
3 ms |
856 KB |
Output is correct |
37 |
Correct |
3 ms |
784 KB |
Output is correct |
38 |
Correct |
3 ms |
852 KB |
Output is correct |
39 |
Correct |
3 ms |
852 KB |
Output is correct |
40 |
Correct |
3 ms |
852 KB |
Output is correct |
41 |
Correct |
3 ms |
852 KB |
Output is correct |
42 |
Correct |
3 ms |
852 KB |
Output is correct |
43 |
Correct |
3 ms |
852 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
3 ms |
852 KB |
Output is correct |
46 |
Correct |
3 ms |
852 KB |
Output is correct |
47 |
Correct |
3 ms |
832 KB |
Output is correct |
48 |
Correct |
3 ms |
852 KB |
Output is correct |
49 |
Correct |
3 ms |
852 KB |
Output is correct |
50 |
Correct |
3 ms |
852 KB |
Output is correct |
51 |
Correct |
3 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
852 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
832 KB |
Output is correct |
30 |
Correct |
3 ms |
832 KB |
Output is correct |
31 |
Correct |
3 ms |
848 KB |
Output is correct |
32 |
Correct |
3 ms |
852 KB |
Output is correct |
33 |
Correct |
3 ms |
788 KB |
Output is correct |
34 |
Correct |
3 ms |
852 KB |
Output is correct |
35 |
Correct |
3 ms |
852 KB |
Output is correct |
36 |
Correct |
3 ms |
856 KB |
Output is correct |
37 |
Correct |
3 ms |
784 KB |
Output is correct |
38 |
Correct |
3 ms |
852 KB |
Output is correct |
39 |
Correct |
3 ms |
852 KB |
Output is correct |
40 |
Correct |
3 ms |
852 KB |
Output is correct |
41 |
Correct |
3 ms |
852 KB |
Output is correct |
42 |
Correct |
3 ms |
852 KB |
Output is correct |
43 |
Correct |
3 ms |
852 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
3 ms |
852 KB |
Output is correct |
46 |
Correct |
3 ms |
852 KB |
Output is correct |
47 |
Correct |
3 ms |
832 KB |
Output is correct |
48 |
Correct |
3 ms |
852 KB |
Output is correct |
49 |
Correct |
3 ms |
852 KB |
Output is correct |
50 |
Correct |
3 ms |
852 KB |
Output is correct |
51 |
Correct |
3 ms |
852 KB |
Output is correct |
52 |
Correct |
391 ms |
54112 KB |
Output is correct |
53 |
Correct |
385 ms |
53984 KB |
Output is correct |
54 |
Correct |
378 ms |
54088 KB |
Output is correct |
55 |
Correct |
407 ms |
54028 KB |
Output is correct |
56 |
Correct |
372 ms |
54220 KB |
Output is correct |
57 |
Correct |
433 ms |
53948 KB |
Output is correct |
58 |
Correct |
430 ms |
54236 KB |
Output is correct |
59 |
Correct |
432 ms |
54060 KB |
Output is correct |
60 |
Correct |
422 ms |
54092 KB |
Output is correct |
61 |
Correct |
412 ms |
53880 KB |
Output is correct |
62 |
Correct |
385 ms |
53968 KB |
Output is correct |
63 |
Correct |
357 ms |
54128 KB |
Output is correct |
64 |
Correct |
347 ms |
53960 KB |
Output is correct |
65 |
Correct |
358 ms |
54160 KB |
Output is correct |
66 |
Correct |
362 ms |
54032 KB |
Output is correct |
67 |
Correct |
372 ms |
54156 KB |
Output is correct |
68 |
Correct |
364 ms |
54060 KB |
Output is correct |