답안 #576267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576267 2022-06-12T20:32:23 Z four_specks Art Exhibition (JOI18_art) C++17
100 / 100
215 ms 28744 KB
#include <bits/stdc++.h>

using namespace std;

inline namespace
{
} // namespace

void solve()
{
    int n;
    cin >> n;

    vector<array<long, 2>> v(n);
    for (auto &[a, b] : v)
        cin >> a >> b;
    sort(v.begin(), v.end());

    vector<long> pref(n + 1, 0);
    for (int i = 0; i < n; i++)
        pref[i + 1] = pref[i] + v[i][1];

    vector diff(pref.begin() + 1, pref.end());
    for (int i = 0; i < n; i++)
        diff[i] -= v[i][0];

    long res = 0;

    long cur = LONG_MIN / 2;
    for (int i = n - 1; i >= 0; i--)
    {
        cur = max(cur, diff[i]);
        res = max(res, cur + v[i][0] - pref[i]);
    }

    cout << res << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL);

    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 224 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 324 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 224 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 324 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 2 ms 584 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 512 KB Output is correct
32 Correct 2 ms 568 KB Output is correct
33 Correct 3 ms 596 KB Output is correct
34 Correct 2 ms 572 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 2 ms 584 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 3 ms 520 KB Output is correct
42 Correct 3 ms 516 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 592 KB Output is correct
45 Correct 2 ms 596 KB Output is correct
46 Correct 3 ms 596 KB Output is correct
47 Correct 3 ms 524 KB Output is correct
48 Correct 2 ms 508 KB Output is correct
49 Correct 2 ms 592 KB Output is correct
50 Correct 2 ms 592 KB Output is correct
51 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 224 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 324 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 2 ms 584 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 512 KB Output is correct
32 Correct 2 ms 568 KB Output is correct
33 Correct 3 ms 596 KB Output is correct
34 Correct 2 ms 572 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 2 ms 584 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 3 ms 520 KB Output is correct
42 Correct 3 ms 516 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 592 KB Output is correct
45 Correct 2 ms 596 KB Output is correct
46 Correct 3 ms 596 KB Output is correct
47 Correct 3 ms 524 KB Output is correct
48 Correct 2 ms 508 KB Output is correct
49 Correct 2 ms 592 KB Output is correct
50 Correct 2 ms 592 KB Output is correct
51 Correct 2 ms 596 KB Output is correct
52 Correct 188 ms 28552 KB Output is correct
53 Correct 181 ms 28740 KB Output is correct
54 Correct 184 ms 28616 KB Output is correct
55 Correct 182 ms 28624 KB Output is correct
56 Correct 185 ms 28624 KB Output is correct
57 Correct 213 ms 28616 KB Output is correct
58 Correct 177 ms 28624 KB Output is correct
59 Correct 182 ms 28620 KB Output is correct
60 Correct 188 ms 28744 KB Output is correct
61 Correct 179 ms 28596 KB Output is correct
62 Correct 180 ms 28596 KB Output is correct
63 Correct 196 ms 28608 KB Output is correct
64 Correct 215 ms 28616 KB Output is correct
65 Correct 181 ms 28616 KB Output is correct
66 Correct 192 ms 28620 KB Output is correct
67 Correct 178 ms 28612 KB Output is correct
68 Correct 190 ms 28616 KB Output is correct