Submission #954973

# Submission time Handle Problem Language Result Execution time Memory
954973 2024-03-29T03:39:02 Z hoanganh_siuuuuuuuu Art Exhibition (JOI18_art) C++17
100 / 100
142 ms 25068 KB
#include <bits/stdc++.h>
#define int long long
#define f(i, a, b) for(int i = a; i <= b; i++)
#define fr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define in insert
#define vvec vector<vector<int>>
#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const int N = 5e5 + 5;
int n, k, f[N];
pii a[N];
vector <int> z;

void sub1()
{
    int res = 0;
    f(i, 1, n)
    {
        int s = 0, mn = 1e17, mx = 0;
        f(j, i, n)
        {
            s += a[j].se;
            mn = min(mn, a[j].fi);
            mx = max(mx, a[j].fi);
            res = max(res, s - (mx - mn));
        }
    }
    cout << res;
}

void sub2()
{
    int mn = a[1].fi, res = 0;
    f(i, 1, n) f[i] = f[i - 1] + a[i].se;
    f(i, 1, n)
    {
        //cout << a[i].fi << " " << a[i].se << "\n";
        //cout << f[i] << " " << mn << "\n";
        res = max(res, f[i] + a[i].fi - mn);
        mn = min(mn, f[i] + a[i + 1].fi);
    }
    cout << res;
}

signed main()
{
    fast;
    cin >> n;
    f(i, 1, n) cin >> a[i].fi >> a[i].se;
    sort(a + 1, a + n + 1, greater <pii> {});

    //sub1();
    sub2();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 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 1 ms 756 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 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 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 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 1 ms 756 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 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 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 860 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 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 608 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 608 KB Output is correct
43 Correct 2 ms 800 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 2 ms 624 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 2 ms 604 KB Output is correct
50 Correct 2 ms 604 KB Output is correct
51 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 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 1 ms 756 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 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 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 860 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 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 608 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 608 KB Output is correct
43 Correct 2 ms 800 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 2 ms 624 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 2 ms 604 KB Output is correct
50 Correct 2 ms 604 KB Output is correct
51 Correct 2 ms 604 KB Output is correct
52 Correct 128 ms 24548 KB Output is correct
53 Correct 142 ms 24832 KB Output is correct
54 Correct 126 ms 24660 KB Output is correct
55 Correct 127 ms 24808 KB Output is correct
56 Correct 134 ms 24820 KB Output is correct
57 Correct 131 ms 24792 KB Output is correct
58 Correct 128 ms 24824 KB Output is correct
59 Correct 134 ms 24824 KB Output is correct
60 Correct 127 ms 25068 KB Output is correct
61 Correct 126 ms 24656 KB Output is correct
62 Correct 136 ms 24828 KB Output is correct
63 Correct 126 ms 24672 KB Output is correct
64 Correct 138 ms 25024 KB Output is correct
65 Correct 131 ms 24688 KB Output is correct
66 Correct 131 ms 24676 KB Output is correct
67 Correct 139 ms 24708 KB Output is correct
68 Correct 140 ms 24824 KB Output is correct