Submission #884196

# Submission time Handle Problem Language Result Execution time Memory
884196 2023-12-06T17:38:47 Z TahirAliyev Art Exhibition (JOI18_art) C++17
100 / 100
478 ms 40700 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define int ll
#define pii pair<ll, ll>
#define oo 1e18
#define all(v) v.begin(), v.end()

int n;
const int MAX = 5e5 + 5;
pii arr[MAX];
int pre[MAX];
int tree[4 * MAX];

void build(int node, int l, int r){
    if(l == r){
        tree[node] = pre[l] - arr[l].first; 
        return;
    }
    int mid = (l + r) / 2;
    build(2 * node, l, mid);
    build(2 * node + 1, mid + 1, r);
    tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}

int ask(int node, int l, int r, int ql, int qr){
    if(qr < l | r < ql) return -oo;
    if(ql <= l && r <= qr) return tree[node];
    int mid = (l + r) / 2;
    return max(ask(2 * node, l, mid, ql, qr), ask(2 * node + 1, mid + 1, r, ql, qr));
}

signed main(){
    fill(tree, tree + 4 * MAX, -oo);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> arr[i].first >> arr[i].second;
    sort(arr + 1, arr + n + 1);
    for(int i = 1; i <= n; i++){
        pre[i] = pre[i - 1] + arr[i].second;
    }
    build(1, 1, n);
    int upd = 0;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans, ask(1, 1, n, i, n) + upd + arr[i].first);
        upd -= arr[i].second;
    }
    cout << ans << '\n';
}

Compilation message

art.cpp: In function 'long long int ask(long long int, long long int, long long int, long long int, long long int)':
art.cpp:29:11: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   29 |     if(qr < l | r < ql) return -oo;
      |        ~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 3 ms 19084 KB Output is correct
3 Correct 3 ms 19036 KB Output is correct
4 Correct 3 ms 19076 KB Output is correct
5 Correct 4 ms 19036 KB Output is correct
6 Correct 4 ms 19036 KB Output is correct
7 Correct 3 ms 19036 KB Output is correct
8 Correct 3 ms 19036 KB Output is correct
9 Correct 3 ms 19032 KB Output is correct
10 Correct 3 ms 19036 KB Output is correct
11 Correct 3 ms 19036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 3 ms 19084 KB Output is correct
3 Correct 3 ms 19036 KB Output is correct
4 Correct 3 ms 19076 KB Output is correct
5 Correct 4 ms 19036 KB Output is correct
6 Correct 4 ms 19036 KB Output is correct
7 Correct 3 ms 19036 KB Output is correct
8 Correct 3 ms 19036 KB Output is correct
9 Correct 3 ms 19032 KB Output is correct
10 Correct 3 ms 19036 KB Output is correct
11 Correct 3 ms 19036 KB Output is correct
12 Correct 4 ms 19036 KB Output is correct
13 Correct 3 ms 19092 KB Output is correct
14 Correct 3 ms 19036 KB Output is correct
15 Correct 3 ms 19036 KB Output is correct
16 Correct 3 ms 19036 KB Output is correct
17 Correct 3 ms 19032 KB Output is correct
18 Correct 4 ms 19032 KB Output is correct
19 Correct 3 ms 19036 KB Output is correct
20 Correct 3 ms 19036 KB Output is correct
21 Correct 3 ms 19036 KB Output is correct
22 Correct 3 ms 19092 KB Output is correct
23 Correct 4 ms 19036 KB Output is correct
24 Correct 3 ms 19036 KB Output is correct
25 Correct 3 ms 19036 KB Output is correct
26 Correct 3 ms 19036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 3 ms 19084 KB Output is correct
3 Correct 3 ms 19036 KB Output is correct
4 Correct 3 ms 19076 KB Output is correct
5 Correct 4 ms 19036 KB Output is correct
6 Correct 4 ms 19036 KB Output is correct
7 Correct 3 ms 19036 KB Output is correct
8 Correct 3 ms 19036 KB Output is correct
9 Correct 3 ms 19032 KB Output is correct
10 Correct 3 ms 19036 KB Output is correct
11 Correct 3 ms 19036 KB Output is correct
12 Correct 4 ms 19036 KB Output is correct
13 Correct 3 ms 19092 KB Output is correct
14 Correct 3 ms 19036 KB Output is correct
15 Correct 3 ms 19036 KB Output is correct
16 Correct 3 ms 19036 KB Output is correct
17 Correct 3 ms 19032 KB Output is correct
18 Correct 4 ms 19032 KB Output is correct
19 Correct 3 ms 19036 KB Output is correct
20 Correct 3 ms 19036 KB Output is correct
21 Correct 3 ms 19036 KB Output is correct
22 Correct 3 ms 19092 KB Output is correct
23 Correct 4 ms 19036 KB Output is correct
24 Correct 3 ms 19036 KB Output is correct
25 Correct 3 ms 19036 KB Output is correct
26 Correct 3 ms 19036 KB Output is correct
27 Correct 7 ms 19036 KB Output is correct
28 Correct 7 ms 19036 KB Output is correct
29 Correct 7 ms 19036 KB Output is correct
30 Correct 7 ms 19096 KB Output is correct
31 Correct 7 ms 19036 KB Output is correct
32 Correct 8 ms 19196 KB Output is correct
33 Correct 7 ms 19036 KB Output is correct
34 Correct 8 ms 19036 KB Output is correct
35 Correct 7 ms 19036 KB Output is correct
36 Correct 9 ms 19032 KB Output is correct
37 Correct 7 ms 19032 KB Output is correct
38 Correct 7 ms 19032 KB Output is correct
39 Correct 8 ms 19036 KB Output is correct
40 Correct 7 ms 19192 KB Output is correct
41 Correct 8 ms 19208 KB Output is correct
42 Correct 7 ms 19036 KB Output is correct
43 Correct 7 ms 19036 KB Output is correct
44 Correct 7 ms 19092 KB Output is correct
45 Correct 7 ms 19092 KB Output is correct
46 Correct 7 ms 19032 KB Output is correct
47 Correct 7 ms 19036 KB Output is correct
48 Correct 8 ms 19292 KB Output is correct
49 Correct 7 ms 19216 KB Output is correct
50 Correct 7 ms 19132 KB Output is correct
51 Correct 7 ms 19036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 3 ms 19084 KB Output is correct
3 Correct 3 ms 19036 KB Output is correct
4 Correct 3 ms 19076 KB Output is correct
5 Correct 4 ms 19036 KB Output is correct
6 Correct 4 ms 19036 KB Output is correct
7 Correct 3 ms 19036 KB Output is correct
8 Correct 3 ms 19036 KB Output is correct
9 Correct 3 ms 19032 KB Output is correct
10 Correct 3 ms 19036 KB Output is correct
11 Correct 3 ms 19036 KB Output is correct
12 Correct 4 ms 19036 KB Output is correct
13 Correct 3 ms 19092 KB Output is correct
14 Correct 3 ms 19036 KB Output is correct
15 Correct 3 ms 19036 KB Output is correct
16 Correct 3 ms 19036 KB Output is correct
17 Correct 3 ms 19032 KB Output is correct
18 Correct 4 ms 19032 KB Output is correct
19 Correct 3 ms 19036 KB Output is correct
20 Correct 3 ms 19036 KB Output is correct
21 Correct 3 ms 19036 KB Output is correct
22 Correct 3 ms 19092 KB Output is correct
23 Correct 4 ms 19036 KB Output is correct
24 Correct 3 ms 19036 KB Output is correct
25 Correct 3 ms 19036 KB Output is correct
26 Correct 3 ms 19036 KB Output is correct
27 Correct 7 ms 19036 KB Output is correct
28 Correct 7 ms 19036 KB Output is correct
29 Correct 7 ms 19036 KB Output is correct
30 Correct 7 ms 19096 KB Output is correct
31 Correct 7 ms 19036 KB Output is correct
32 Correct 8 ms 19196 KB Output is correct
33 Correct 7 ms 19036 KB Output is correct
34 Correct 8 ms 19036 KB Output is correct
35 Correct 7 ms 19036 KB Output is correct
36 Correct 9 ms 19032 KB Output is correct
37 Correct 7 ms 19032 KB Output is correct
38 Correct 7 ms 19032 KB Output is correct
39 Correct 8 ms 19036 KB Output is correct
40 Correct 7 ms 19192 KB Output is correct
41 Correct 8 ms 19208 KB Output is correct
42 Correct 7 ms 19036 KB Output is correct
43 Correct 7 ms 19036 KB Output is correct
44 Correct 7 ms 19092 KB Output is correct
45 Correct 7 ms 19092 KB Output is correct
46 Correct 7 ms 19032 KB Output is correct
47 Correct 7 ms 19036 KB Output is correct
48 Correct 8 ms 19292 KB Output is correct
49 Correct 7 ms 19216 KB Output is correct
50 Correct 7 ms 19132 KB Output is correct
51 Correct 7 ms 19036 KB Output is correct
52 Correct 421 ms 40172 KB Output is correct
53 Correct 427 ms 40408 KB Output is correct
54 Correct 431 ms 40296 KB Output is correct
55 Correct 420 ms 40276 KB Output is correct
56 Correct 424 ms 40476 KB Output is correct
57 Correct 444 ms 40476 KB Output is correct
58 Correct 425 ms 40700 KB Output is correct
59 Correct 434 ms 40272 KB Output is correct
60 Correct 426 ms 40292 KB Output is correct
61 Correct 427 ms 40532 KB Output is correct
62 Correct 424 ms 40292 KB Output is correct
63 Correct 478 ms 40452 KB Output is correct
64 Correct 421 ms 40276 KB Output is correct
65 Correct 438 ms 40432 KB Output is correct
66 Correct 426 ms 40424 KB Output is correct
67 Correct 432 ms 40296 KB Output is correct
68 Correct 430 ms 40532 KB Output is correct