답안 #704524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704524 2023-03-02T08:58:43 Z KenIsGenius Art Exhibition (JOI18_art) C++17
100 / 100
192 ms 21764 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define int long long
using namespace std;

#ifdef LOCAL
#define WOSAOJI freopen("in.txt", "r", stdin);
#else
#define WOSAOJI ios_base::sync_with_stdio(0), cin.tie(0);
#endif

#define chmax(a, b) (a) = (a) > (b) ? (a) : (b)
#define chmin(a, b) (a) = (a) < (b) ? (a) : (b)

const int MAXN = 5e5 + 5;
int n, s;
pair<int, int> a[MAXN];
int p_min[MAXN], p_max[MAXN];
int pre[MAXN];
signed main() {
    WOSAOJI
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].F >> a[i].S;
        s += a[i].S;
    }
    sort(a + 1, a + 1 + n);
    int cur = s - a[n].F + a[1].F;
    for (int i = 1; i < n; i++) {
        p_min[i] = a[i + 1].F - a[i].F - a[i].S;
        p_min[i] += p_min[i - 1];
        pre[i] = max(pre[i - 1], p_min[i]);
    }
    for (int i = n; i > 1; i--) {
        p_max[i] = a[i].F - a[i].S - a[i - 1].F;
        p_max[i] += p_max[i + 1];
    }
    for (int i = 1; i <= n; i++) {
        //cout << p_min[i] << " \n"[i == n];
    }
    for (int i = 1; i <= n; i++) {
        //cout << p_max[i] << " \n"[i == n];
    }
    int ans = max(0ll, cur);
    for (int i = 2; i <= n + 1; i++) {
        chmax(ans, cur + p_max[i] + pre[i - 2]);
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 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 336 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 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 336 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 4 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 2 ms 580 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 652 KB Output is correct
36 Correct 2 ms 600 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 3 ms 656 KB Output is correct
39 Correct 2 ms 624 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 4 ms 664 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 3 ms 584 KB Output is correct
46 Correct 3 ms 576 KB Output is correct
47 Correct 3 ms 600 KB Output is correct
48 Correct 3 ms 596 KB Output is correct
49 Correct 3 ms 596 KB Output is correct
50 Correct 2 ms 596 KB Output is correct
51 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 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 336 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 4 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 2 ms 580 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 652 KB Output is correct
36 Correct 2 ms 600 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 3 ms 656 KB Output is correct
39 Correct 2 ms 624 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 4 ms 664 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 3 ms 584 KB Output is correct
46 Correct 3 ms 576 KB Output is correct
47 Correct 3 ms 600 KB Output is correct
48 Correct 3 ms 596 KB Output is correct
49 Correct 3 ms 596 KB Output is correct
50 Correct 2 ms 596 KB Output is correct
51 Correct 3 ms 596 KB Output is correct
52 Correct 176 ms 21600 KB Output is correct
53 Correct 172 ms 21596 KB Output is correct
54 Correct 177 ms 21560 KB Output is correct
55 Correct 192 ms 21648 KB Output is correct
56 Correct 169 ms 21580 KB Output is correct
57 Correct 177 ms 21608 KB Output is correct
58 Correct 169 ms 21632 KB Output is correct
59 Correct 173 ms 21644 KB Output is correct
60 Correct 176 ms 21632 KB Output is correct
61 Correct 174 ms 21712 KB Output is correct
62 Correct 183 ms 21572 KB Output is correct
63 Correct 172 ms 21764 KB Output is correct
64 Correct 186 ms 21624 KB Output is correct
65 Correct 173 ms 21584 KB Output is correct
66 Correct 176 ms 21576 KB Output is correct
67 Correct 176 ms 21660 KB Output is correct
68 Correct 164 ms 21576 KB Output is correct