Submission #787641

# Submission time Handle Problem Language Result Execution time Memory
787641 2023-07-19T10:37:34 Z That_Salamander Art Exhibition (JOI18_art) C++17
100 / 100
309 ms 63948 KB
#include <bits/stdc++.h>
#define int long long

#define FOR(var,bound) for(int var = 0; var < bound; var++)
#define FORB(var,lb,ub) for (int var = lb; var < ub; var++)
#define FORR(var,bound) for(int var = bound-1; var >= 0; var--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

int n;
pii art[500000];
int prefixValue[500005], adjustedValue[500005], prefixAdjusted[500005];

int getValue(int l, int r) {
    int s = prefixValue[r+1] - prefixValue[l];
    return s - (art[r].first - art[l].first);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;
    FOR(i, n) {
        cin >> art[i].first >> art[i].second;
    }

    sort(art, art + n);

    prefixValue[0] = 0;

    FOR(i, n) {
        prefixValue[i+1] = prefixValue[i] + art[i].second;
    }

    prefixAdjusted[0] = 0;
    set<pii> bruh;
    FOR (i, n) {
        if (i == 0) {
            adjustedValue[i] = art[i].second;
        } else {
            adjustedValue[i] = art[i].second - (art[i].first - art[i-1].first);
        }

        prefixAdjusted[i+1] = prefixAdjusted[i] + adjustedValue[i];
        bruh.insert({prefixAdjusted[i+1], i});
    }

    int res = 0;

    FOR(i, n) {
        auto mpos = *(--bruh.end());
        res = max(res, getValue(i, mpos.second));
        bruh.erase({prefixAdjusted[i+1], i});
    }

    cout << res << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 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 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 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 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 2 ms 864 KB Output is correct
29 Correct 2 ms 852 KB Output is correct
30 Correct 2 ms 760 KB Output is correct
31 Correct 3 ms 852 KB Output is correct
32 Correct 2 ms 852 KB Output is correct
33 Correct 2 ms 852 KB Output is correct
34 Correct 2 ms 852 KB Output is correct
35 Correct 3 ms 852 KB Output is correct
36 Correct 3 ms 852 KB Output is correct
37 Correct 2 ms 852 KB Output is correct
38 Correct 3 ms 852 KB Output is correct
39 Correct 3 ms 852 KB Output is correct
40 Correct 3 ms 868 KB Output is correct
41 Correct 2 ms 852 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 2 ms 864 KB Output is correct
44 Correct 2 ms 852 KB Output is correct
45 Correct 2 ms 852 KB Output is correct
46 Correct 3 ms 852 KB Output is correct
47 Correct 2 ms 852 KB Output is correct
48 Correct 2 ms 852 KB Output is correct
49 Correct 2 ms 852 KB Output is correct
50 Correct 2 ms 852 KB Output is correct
51 Correct 2 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 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 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 2 ms 864 KB Output is correct
29 Correct 2 ms 852 KB Output is correct
30 Correct 2 ms 760 KB Output is correct
31 Correct 3 ms 852 KB Output is correct
32 Correct 2 ms 852 KB Output is correct
33 Correct 2 ms 852 KB Output is correct
34 Correct 2 ms 852 KB Output is correct
35 Correct 3 ms 852 KB Output is correct
36 Correct 3 ms 852 KB Output is correct
37 Correct 2 ms 852 KB Output is correct
38 Correct 3 ms 852 KB Output is correct
39 Correct 3 ms 852 KB Output is correct
40 Correct 3 ms 868 KB Output is correct
41 Correct 2 ms 852 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 2 ms 864 KB Output is correct
44 Correct 2 ms 852 KB Output is correct
45 Correct 2 ms 852 KB Output is correct
46 Correct 3 ms 852 KB Output is correct
47 Correct 2 ms 852 KB Output is correct
48 Correct 2 ms 852 KB Output is correct
49 Correct 2 ms 852 KB Output is correct
50 Correct 2 ms 852 KB Output is correct
51 Correct 2 ms 852 KB Output is correct
52 Correct 239 ms 51104 KB Output is correct
53 Correct 237 ms 63792 KB Output is correct
54 Correct 251 ms 63788 KB Output is correct
55 Correct 270 ms 63840 KB Output is correct
56 Correct 309 ms 63744 KB Output is correct
57 Correct 302 ms 63812 KB Output is correct
58 Correct 291 ms 63776 KB Output is correct
59 Correct 267 ms 63912 KB Output is correct
60 Correct 266 ms 63760 KB Output is correct
61 Correct 260 ms 63760 KB Output is correct
62 Correct 260 ms 63948 KB Output is correct
63 Correct 254 ms 63768 KB Output is correct
64 Correct 272 ms 63932 KB Output is correct
65 Correct 226 ms 63828 KB Output is correct
66 Correct 220 ms 63748 KB Output is correct
67 Correct 246 ms 63868 KB Output is correct
68 Correct 264 ms 63800 KB Output is correct