Submission #858149

# Submission time Handle Problem Language Result Execution time Memory
858149 2023-10-07T13:37:47 Z thangdz2k7 Fuel Station (NOI20_fuelstation) C++17
55 / 100
188 ms 15884 KB
#include <bits/stdc++.h>
#define ii pair <int, int>
#define F first
#define S second

using namespace std;

const int mod = 1e9 + 7;
const int N = 3e5 + 5;

int n, d, a[N], b[N], x[N];
int sr[N], t[N];

int Max[4 * N], lazy[4 * N];

void build(int s, int l, int r){
    if (l == r){
        Max[s] = sr[l];
        return;
    }
    int mid = l + r >> 1;
    build(2 * s, l, mid);
    build(2 * s + 1, mid + 1, r);
    Max[s] = max(Max[2 * s], Max[2 * s + 1]);
}

void update(int s, int l, int r, int u, int val){
    if (u <= l){
        lazy[s] += val;
        Max[s] += val;
        return;
    }
    int mid = l + r >> 1;
    if (mid >= u) update(2 * s, l, mid, u, val);
    update(2 * s + 1, mid + 1, r, u, val);
    Max[s] = max(Max[2 * s], Max[2 * s + 1]) + lazy[s];
}

void solve(){
    cin >> n >> d;
    for (int i = 1; i <= n; ++ i) {
        cin >> x[i] >> a[i] >> b[i];
        sr[i] = x[i];
        t[i] = i;
    }
    ++ n;
    x[n] = d;
    sr[n] = d;
    a[n] = 0;
    t[n] = n;
    sort(sr + 1, sr + n + 1);
    for (int i = 1; i <= n; ++ i) x[i] = lower_bound(sr + 1, sr + n + 1, x[i]) - sr;
    sort(t + 1, t + n + 1, [&](int u, int v){
         return b[u] > b[v];
    });

    int ans = d;
    build(1, 1, n);
    for (int z = 1; z <= n; ++ z){
        //cout << Max[1] << endl;
        int i = t[z];
        if (x[i] + 1 <= n) update(1, 1, n, x[i] + 1, -a[i]);
        if (Max[1] <= b[i]) ans = Max[1];
    }

    cout << max(0, ans);
}

int main(){
    //freopen("code.inp", "r", stdin);
    //freopen("code.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    while (t --) solve();

    return 0;
}

Compilation message

FuelStation.cpp: In function 'void build(int, int, int)':
FuelStation.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |     int mid = l + r >> 1;
      |               ~~^~~
FuelStation.cpp: In function 'void update(int, int, int, int, int)':
FuelStation.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8536 KB Output is correct
9 Correct 1 ms 8696 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 188 ms 15476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 5 ms 8536 KB Output is correct
3 Correct 6 ms 8796 KB Output is correct
4 Correct 7 ms 8672 KB Output is correct
5 Correct 7 ms 8800 KB Output is correct
6 Correct 6 ms 8796 KB Output is correct
7 Correct 6 ms 8792 KB Output is correct
8 Correct 1 ms 8536 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8660 KB Output is correct
14 Correct 6 ms 8672 KB Output is correct
15 Correct 6 ms 8796 KB Output is correct
16 Correct 6 ms 8792 KB Output is correct
17 Correct 6 ms 8664 KB Output is correct
18 Correct 6 ms 8668 KB Output is correct
19 Correct 5 ms 8540 KB Output is correct
20 Correct 6 ms 8796 KB Output is correct
21 Correct 5 ms 8796 KB Output is correct
22 Correct 5 ms 8540 KB Output is correct
23 Correct 5 ms 8540 KB Output is correct
24 Correct 5 ms 8540 KB Output is correct
25 Correct 5 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 5 ms 8536 KB Output is correct
3 Correct 6 ms 8796 KB Output is correct
4 Correct 7 ms 8672 KB Output is correct
5 Correct 7 ms 8800 KB Output is correct
6 Correct 6 ms 8796 KB Output is correct
7 Correct 6 ms 8792 KB Output is correct
8 Correct 1 ms 8536 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8660 KB Output is correct
14 Correct 6 ms 8672 KB Output is correct
15 Correct 6 ms 8796 KB Output is correct
16 Correct 6 ms 8792 KB Output is correct
17 Correct 6 ms 8664 KB Output is correct
18 Correct 6 ms 8668 KB Output is correct
19 Correct 5 ms 8540 KB Output is correct
20 Correct 6 ms 8796 KB Output is correct
21 Correct 5 ms 8796 KB Output is correct
22 Correct 5 ms 8540 KB Output is correct
23 Correct 5 ms 8540 KB Output is correct
24 Correct 5 ms 8540 KB Output is correct
25 Correct 5 ms 8796 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 164 ms 15700 KB Output is correct
28 Correct 169 ms 15700 KB Output is correct
29 Correct 165 ms 15696 KB Output is correct
30 Correct 164 ms 15704 KB Output is correct
31 Correct 183 ms 15884 KB Output is correct
32 Correct 172 ms 15644 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 1 ms 8540 KB Output is correct
35 Correct 1 ms 8540 KB Output is correct
36 Correct 1 ms 8656 KB Output is correct
37 Correct 1 ms 8536 KB Output is correct
38 Correct 1 ms 8540 KB Output is correct
39 Correct 165 ms 15508 KB Output is correct
40 Correct 165 ms 15696 KB Output is correct
41 Correct 165 ms 15624 KB Output is correct
42 Correct 170 ms 15692 KB Output is correct
43 Correct 179 ms 15512 KB Output is correct
44 Correct 163 ms 15508 KB Output is correct
45 Correct 148 ms 15692 KB Output is correct
46 Correct 182 ms 15700 KB Output is correct
47 Correct 150 ms 15660 KB Output is correct
48 Correct 154 ms 15696 KB Output is correct
49 Correct 161 ms 15696 KB Output is correct
50 Correct 167 ms 15696 KB Output is correct
51 Correct 158 ms 15700 KB Output is correct
52 Correct 155 ms 15684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8536 KB Output is correct
9 Correct 1 ms 8696 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 0 ms 8692 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8536 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8536 KB Output is correct
26 Correct 1 ms 8536 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8536 KB Output is correct
9 Correct 1 ms 8696 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 5 ms 8536 KB Output is correct
18 Correct 6 ms 8796 KB Output is correct
19 Correct 7 ms 8672 KB Output is correct
20 Correct 7 ms 8800 KB Output is correct
21 Correct 6 ms 8796 KB Output is correct
22 Correct 6 ms 8792 KB Output is correct
23 Correct 1 ms 8536 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8660 KB Output is correct
29 Correct 6 ms 8672 KB Output is correct
30 Correct 6 ms 8796 KB Output is correct
31 Correct 6 ms 8792 KB Output is correct
32 Correct 6 ms 8664 KB Output is correct
33 Correct 6 ms 8668 KB Output is correct
34 Correct 5 ms 8540 KB Output is correct
35 Correct 6 ms 8796 KB Output is correct
36 Correct 5 ms 8796 KB Output is correct
37 Correct 5 ms 8540 KB Output is correct
38 Correct 5 ms 8540 KB Output is correct
39 Correct 5 ms 8540 KB Output is correct
40 Correct 5 ms 8796 KB Output is correct
41 Correct 1 ms 8540 KB Output is correct
42 Correct 6 ms 8540 KB Output is correct
43 Correct 6 ms 8792 KB Output is correct
44 Incorrect 6 ms 8796 KB Output isn't correct
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8536 KB Output is correct
9 Correct 1 ms 8696 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Incorrect 188 ms 15476 KB Output isn't correct
17 Halted 0 ms 0 KB -