Submission #375370

# Submission time Handle Problem Language Result Execution time Memory
375370 2021-03-09T10:16:51 Z Alex_tz307 Art Exhibition (JOI18_art) C++17
100 / 100
397 ms 107244 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int NMAX = 5e5 + 5;
int N, pref_sum[NMAX], lg2[NMAX], rmq_max[NMAX][20], ans;
pair<int,int> a[NMAX];

void compute_lg2() {
    lg2[1] = 0;
    for(int i = 2; i <= N; ++i)
        lg2[i] = lg2[i >> 1] + 1;
}

void compute_rmq() {
    for(int i = 1; i <= N; ++i)
        rmq_max[i][0] = pref_sum[i] - a[i].first;
    for(int j = 1; (1 << j) <= N; ++j)
        for(int i = 1; i + (1 << j) - 1 <= N; ++i)
            rmq_max[i][j] = max(rmq_max[i][j - 1], rmq_max[i + (1 << (j - 1))][j - 1]);
}

int query_max(int l, int r) {
    int k = lg2[r - l + 1];
    int dif = (r - l + 1) - (1 << k);
    return max(rmq_max[l][k], rmq_max[l + dif][k]);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> N;
    for(int i = 1; i <= N; ++i)
        cin >> a[i].first >> a[i].second;
    sort(a + 1, a + N + 1);
    for(int i = 1; i <= N; ++i)
        pref_sum[i] = pref_sum[i - 1] + a[i].second;
    compute_lg2();
    compute_rmq();
    for(int i = 1; i <= N; ++i) {
        int best = a[i].first + query_max(i, N) - pref_sum[i - 1];
        ans = max(ans, best);
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 404 KB Output is correct
27 Correct 3 ms 1388 KB Output is correct
28 Correct 3 ms 1388 KB Output is correct
29 Correct 3 ms 1408 KB Output is correct
30 Correct 3 ms 1388 KB Output is correct
31 Correct 5 ms 1388 KB Output is correct
32 Correct 4 ms 1400 KB Output is correct
33 Correct 3 ms 1388 KB Output is correct
34 Correct 3 ms 1388 KB Output is correct
35 Correct 3 ms 1388 KB Output is correct
36 Correct 3 ms 1388 KB Output is correct
37 Correct 3 ms 1416 KB Output is correct
38 Correct 3 ms 1388 KB Output is correct
39 Correct 3 ms 1388 KB Output is correct
40 Correct 3 ms 1388 KB Output is correct
41 Correct 3 ms 1388 KB Output is correct
42 Correct 3 ms 1388 KB Output is correct
43 Correct 4 ms 1516 KB Output is correct
44 Correct 3 ms 1388 KB Output is correct
45 Correct 3 ms 1388 KB Output is correct
46 Correct 4 ms 1388 KB Output is correct
47 Correct 3 ms 1388 KB Output is correct
48 Correct 3 ms 1388 KB Output is correct
49 Correct 3 ms 1388 KB Output is correct
50 Correct 3 ms 1388 KB Output is correct
51 Correct 4 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 404 KB Output is correct
27 Correct 3 ms 1388 KB Output is correct
28 Correct 3 ms 1388 KB Output is correct
29 Correct 3 ms 1408 KB Output is correct
30 Correct 3 ms 1388 KB Output is correct
31 Correct 5 ms 1388 KB Output is correct
32 Correct 4 ms 1400 KB Output is correct
33 Correct 3 ms 1388 KB Output is correct
34 Correct 3 ms 1388 KB Output is correct
35 Correct 3 ms 1388 KB Output is correct
36 Correct 3 ms 1388 KB Output is correct
37 Correct 3 ms 1416 KB Output is correct
38 Correct 3 ms 1388 KB Output is correct
39 Correct 3 ms 1388 KB Output is correct
40 Correct 3 ms 1388 KB Output is correct
41 Correct 3 ms 1388 KB Output is correct
42 Correct 3 ms 1388 KB Output is correct
43 Correct 4 ms 1516 KB Output is correct
44 Correct 3 ms 1388 KB Output is correct
45 Correct 3 ms 1388 KB Output is correct
46 Correct 4 ms 1388 KB Output is correct
47 Correct 3 ms 1388 KB Output is correct
48 Correct 3 ms 1388 KB Output is correct
49 Correct 3 ms 1388 KB Output is correct
50 Correct 3 ms 1388 KB Output is correct
51 Correct 4 ms 1388 KB Output is correct
52 Correct 363 ms 107008 KB Output is correct
53 Correct 365 ms 106988 KB Output is correct
54 Correct 360 ms 106988 KB Output is correct
55 Correct 359 ms 106988 KB Output is correct
56 Correct 367 ms 106988 KB Output is correct
57 Correct 397 ms 107016 KB Output is correct
58 Correct 364 ms 107244 KB Output is correct
59 Correct 362 ms 106988 KB Output is correct
60 Correct 359 ms 107016 KB Output is correct
61 Correct 361 ms 106860 KB Output is correct
62 Correct 353 ms 106900 KB Output is correct
63 Correct 361 ms 106988 KB Output is correct
64 Correct 362 ms 107244 KB Output is correct
65 Correct 363 ms 106988 KB Output is correct
66 Correct 365 ms 106988 KB Output is correct
67 Correct 360 ms 106988 KB Output is correct
68 Correct 358 ms 106988 KB Output is correct