답안 #1079238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079238 2024-08-28T12:15:02 Z vjudge1 Art Exhibition (JOI18_art) C++17
100 / 100
146 ms 28756 KB
#include <bits/stdc++.h>
#define task "MAXNUM"
#define pl pair<ll, ll>
#define pf push_front
#define pb push_back
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b, c) for (int i=a; i<=b; i+=c)
#define FORE(i, a, b, c) for (int i=a; i>=b; i+=c)
#define VI vector <int>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int Mod = 123456789;
const int maxn = 5e5+1;
const ll Inf = 3e18;
pl A[maxn+1];
ll B[maxn+2], C[maxn+2], sum2, sum, n, res;
void Read()
{
    cin >> n;
    FOR(i, 1, n, 1) {
        cin >> A[i].fi >> A[i].se;
        sum2 += A[i].se;
    }
}
void Solve()
{
    B[0] = -Inf, C[n+1] = -Inf;
    sort (A + 1, A + n + 1);
    FOR(i, 1, n, 1) {
        B[i] = max(B[i-1], A[i].fi - sum);
        sum += A[i].se;
    }
    FORE(i, n, 1, -1) {
        C[i] = max(C[i+1], sum2 - A[i].fi);
        sum2 -= A[i].se;
    }
    //FOR(i, 1, n, 1) cout << B[i] << " " << C[i] << '\n';
    FOR(i, 1, n, 1) {
        res = max(res, C[i] + B[i]);
    }
    cout << res;
}
int main()
{
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    for (t=1; t--;)
    {
        Read(); Solve();
    }
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:51:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:52:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 464 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 464 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 1 ms 648 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 732 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 652 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 600 KB Output is correct
41 Correct 2 ms 856 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 2 ms 600 KB Output is correct
50 Correct 2 ms 600 KB Output is correct
51 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 464 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 1 ms 648 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 732 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 652 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 600 KB Output is correct
41 Correct 2 ms 856 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 2 ms 600 KB Output is correct
50 Correct 2 ms 600 KB Output is correct
51 Correct 2 ms 604 KB Output is correct
52 Correct 122 ms 28520 KB Output is correct
53 Correct 132 ms 28756 KB Output is correct
54 Correct 133 ms 28752 KB Output is correct
55 Correct 122 ms 28752 KB Output is correct
56 Correct 125 ms 28752 KB Output is correct
57 Correct 128 ms 28496 KB Output is correct
58 Correct 123 ms 28496 KB Output is correct
59 Correct 126 ms 28664 KB Output is correct
60 Correct 119 ms 28496 KB Output is correct
61 Correct 126 ms 28420 KB Output is correct
62 Correct 127 ms 28500 KB Output is correct
63 Correct 122 ms 28744 KB Output is correct
64 Correct 128 ms 28664 KB Output is correct
65 Correct 132 ms 28536 KB Output is correct
66 Correct 146 ms 28688 KB Output is correct
67 Correct 123 ms 28664 KB Output is correct
68 Correct 125 ms 28592 KB Output is correct