#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
pair<long long, long long> a[n];
for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
sort(a, a + n);
long long dp1[n], dp2[n];
fill(dp1, dp1 + n, 0);
fill(dp2, dp2 + n, 0);
dp1[0] = a[0].x + a[0].y;
for (int i = 1; i < n; i++) dp1[i] = max(dp1[i - 1] + a[i].y, a[i].x + a[i].y);
dp2[n - 1] = a[n - 1].y - a[n - 1].x;
for (int i = n - 2; i >= 0; i--) dp2[i] = max(dp2[i + 1] + a[i].y, a[i].y - a[i].x);
long long ans = 0;
for (int i = 0; i < n; i++) ans = max(ans, a[i].y);
for (int i = 0; i < n - 1; i++) ans = max(ans, dp1[i] + dp2[i + 1]);
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
1 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
1 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
4 ms |
636 KB |
Output is correct |
29 |
Correct |
5 ms |
632 KB |
Output is correct |
30 |
Correct |
5 ms |
632 KB |
Output is correct |
31 |
Correct |
5 ms |
632 KB |
Output is correct |
32 |
Correct |
5 ms |
632 KB |
Output is correct |
33 |
Correct |
4 ms |
632 KB |
Output is correct |
34 |
Correct |
5 ms |
632 KB |
Output is correct |
35 |
Correct |
4 ms |
632 KB |
Output is correct |
36 |
Correct |
5 ms |
636 KB |
Output is correct |
37 |
Correct |
5 ms |
632 KB |
Output is correct |
38 |
Correct |
5 ms |
632 KB |
Output is correct |
39 |
Correct |
5 ms |
632 KB |
Output is correct |
40 |
Correct |
5 ms |
632 KB |
Output is correct |
41 |
Correct |
4 ms |
632 KB |
Output is correct |
42 |
Correct |
5 ms |
632 KB |
Output is correct |
43 |
Correct |
5 ms |
632 KB |
Output is correct |
44 |
Correct |
5 ms |
632 KB |
Output is correct |
45 |
Correct |
5 ms |
632 KB |
Output is correct |
46 |
Correct |
5 ms |
632 KB |
Output is correct |
47 |
Correct |
4 ms |
632 KB |
Output is correct |
48 |
Correct |
4 ms |
632 KB |
Output is correct |
49 |
Correct |
5 ms |
632 KB |
Output is correct |
50 |
Correct |
4 ms |
632 KB |
Output is correct |
51 |
Correct |
4 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
1 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
4 ms |
636 KB |
Output is correct |
29 |
Correct |
5 ms |
632 KB |
Output is correct |
30 |
Correct |
5 ms |
632 KB |
Output is correct |
31 |
Correct |
5 ms |
632 KB |
Output is correct |
32 |
Correct |
5 ms |
632 KB |
Output is correct |
33 |
Correct |
4 ms |
632 KB |
Output is correct |
34 |
Correct |
5 ms |
632 KB |
Output is correct |
35 |
Correct |
4 ms |
632 KB |
Output is correct |
36 |
Correct |
5 ms |
636 KB |
Output is correct |
37 |
Correct |
5 ms |
632 KB |
Output is correct |
38 |
Correct |
5 ms |
632 KB |
Output is correct |
39 |
Correct |
5 ms |
632 KB |
Output is correct |
40 |
Correct |
5 ms |
632 KB |
Output is correct |
41 |
Correct |
4 ms |
632 KB |
Output is correct |
42 |
Correct |
5 ms |
632 KB |
Output is correct |
43 |
Correct |
5 ms |
632 KB |
Output is correct |
44 |
Correct |
5 ms |
632 KB |
Output is correct |
45 |
Correct |
5 ms |
632 KB |
Output is correct |
46 |
Correct |
5 ms |
632 KB |
Output is correct |
47 |
Correct |
4 ms |
632 KB |
Output is correct |
48 |
Correct |
4 ms |
632 KB |
Output is correct |
49 |
Correct |
5 ms |
632 KB |
Output is correct |
50 |
Correct |
4 ms |
632 KB |
Output is correct |
51 |
Correct |
4 ms |
632 KB |
Output is correct |
52 |
Correct |
258 ms |
28664 KB |
Output is correct |
53 |
Correct |
259 ms |
28664 KB |
Output is correct |
54 |
Correct |
260 ms |
28552 KB |
Output is correct |
55 |
Correct |
261 ms |
28664 KB |
Output is correct |
56 |
Correct |
260 ms |
28656 KB |
Output is correct |
57 |
Correct |
260 ms |
28664 KB |
Output is correct |
58 |
Correct |
259 ms |
28676 KB |
Output is correct |
59 |
Correct |
259 ms |
28576 KB |
Output is correct |
60 |
Correct |
260 ms |
28792 KB |
Output is correct |
61 |
Correct |
259 ms |
28520 KB |
Output is correct |
62 |
Correct |
261 ms |
28664 KB |
Output is correct |
63 |
Correct |
258 ms |
28664 KB |
Output is correct |
64 |
Correct |
258 ms |
28664 KB |
Output is correct |
65 |
Correct |
259 ms |
28664 KB |
Output is correct |
66 |
Correct |
259 ms |
28644 KB |
Output is correct |
67 |
Correct |
258 ms |
28664 KB |
Output is correct |
68 |
Correct |
259 ms |
28664 KB |
Output is correct |