Submission #888944

# Submission time Handle Problem Language Result Execution time Memory
888944 2023-12-18T12:51:41 Z vjudge1 Fuel Station (NOI20_fuelstation) C++17
100 / 100
293 ms 36828 KB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct FUEL {
    long long int x, a, b;
} a[300005];
bool cmp(FUEL aa, FUEL bb) {
    return aa.x < bb.x;
}
long long int t[1200005], lazy[1200005];
void push(int v) {
    t[v * 2] += lazy[v];
    lazy[v * 2] += lazy[v];
    t[v * 2 + 1] += lazy[v];
    lazy[v * 2 + 1] += lazy[v];
    lazy[v] = 0;
}
void update(int v, int tl, int tr, int l, int r, int x) {
    if (l > r) return;
    if (tl == l && tr == r) {
        t[v] += x;
        lazy[v] += x;
        return;
    }
    push(v);
    int mid = (tl + tr) / 2;
    update(v * 2, tl, mid, l, min(r, mid), x);
    update(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r, x);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
}
long long int sum(int v, int tl, int tr, int l, int r) {
    if (l > r) return 0;
    if (tl == l && tr == r) {
        return t[v];
    }
    push(v);
    int mid = (tl + tr) / 2;
    return max(sum(v * 2, tl, mid, l, min(r, mid)), sum(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r));
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long long int n, d, c = 0, res = 1e18;
    cin >> n >> d;
    vector<pair<long long int, int>> v;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].x >> a[i].a >> a[i].b;
    }
    sort(a + 1, a + n + 1, cmp);
    for (int i = 1; i <= n; i++) {
        v.push_back({a[i].b, i});
        update(1, 1, n, i, i, a[i].x);
    }
    sort(v.begin(), v.end(), greater<pair<long long int, int>>());
    res = d;
    for (auto w : v) {
        c += a[w.second].a;
        update(1, 1, n, w.second + 1, n, -a[w.second].a);
        long long int h = max(max(t[1], d - c), 0ll);
        if (h <= w.first) {
            res = min(res, h);
        }
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 34780 KB Output is correct
2 Correct 200 ms 35008 KB Output is correct
3 Correct 214 ms 35444 KB Output is correct
4 Correct 199 ms 35712 KB Output is correct
5 Correct 198 ms 36408 KB Output is correct
6 Correct 200 ms 34744 KB Output is correct
7 Correct 210 ms 35868 KB Output is correct
8 Correct 194 ms 36288 KB Output is correct
9 Correct 201 ms 35892 KB Output is correct
10 Correct 196 ms 35072 KB Output is correct
11 Correct 198 ms 34756 KB Output is correct
12 Correct 209 ms 35008 KB Output is correct
13 Correct 200 ms 35760 KB Output is correct
14 Correct 205 ms 34500 KB Output is correct
15 Correct 196 ms 35780 KB Output is correct
16 Correct 213 ms 36360 KB Output is correct
17 Correct 214 ms 34956 KB Output is correct
18 Correct 201 ms 36424 KB Output is correct
19 Correct 204 ms 36408 KB Output is correct
20 Correct 201 ms 34608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 7 ms 7004 KB Output is correct
3 Correct 7 ms 7084 KB Output is correct
4 Correct 7 ms 7004 KB Output is correct
5 Correct 7 ms 7004 KB Output is correct
6 Correct 9 ms 7004 KB Output is correct
7 Correct 7 ms 7004 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 7 ms 7004 KB Output is correct
15 Correct 7 ms 7004 KB Output is correct
16 Correct 7 ms 7004 KB Output is correct
17 Correct 7 ms 7004 KB Output is correct
18 Correct 7 ms 7132 KB Output is correct
19 Correct 7 ms 7004 KB Output is correct
20 Correct 6 ms 7004 KB Output is correct
21 Correct 6 ms 7000 KB Output is correct
22 Correct 7 ms 7004 KB Output is correct
23 Correct 7 ms 7004 KB Output is correct
24 Correct 7 ms 7004 KB Output is correct
25 Correct 7 ms 7128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 7 ms 7004 KB Output is correct
3 Correct 7 ms 7084 KB Output is correct
4 Correct 7 ms 7004 KB Output is correct
5 Correct 7 ms 7004 KB Output is correct
6 Correct 9 ms 7004 KB Output is correct
7 Correct 7 ms 7004 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 7 ms 7004 KB Output is correct
15 Correct 7 ms 7004 KB Output is correct
16 Correct 7 ms 7004 KB Output is correct
17 Correct 7 ms 7004 KB Output is correct
18 Correct 7 ms 7132 KB Output is correct
19 Correct 7 ms 7004 KB Output is correct
20 Correct 6 ms 7004 KB Output is correct
21 Correct 6 ms 7000 KB Output is correct
22 Correct 7 ms 7004 KB Output is correct
23 Correct 7 ms 7004 KB Output is correct
24 Correct 7 ms 7004 KB Output is correct
25 Correct 7 ms 7128 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 244 ms 35388 KB Output is correct
28 Correct 255 ms 35524 KB Output is correct
29 Correct 270 ms 35524 KB Output is correct
30 Correct 247 ms 35740 KB Output is correct
31 Correct 255 ms 35524 KB Output is correct
32 Correct 257 ms 34504 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 244 ms 35128 KB Output is correct
40 Correct 247 ms 35520 KB Output is correct
41 Correct 244 ms 36032 KB Output is correct
42 Correct 246 ms 34624 KB Output is correct
43 Correct 246 ms 34496 KB Output is correct
44 Correct 212 ms 36420 KB Output is correct
45 Correct 183 ms 35140 KB Output is correct
46 Correct 244 ms 36296 KB Output is correct
47 Correct 188 ms 36032 KB Output is correct
48 Correct 183 ms 36296 KB Output is correct
49 Correct 242 ms 36308 KB Output is correct
50 Correct 247 ms 34496 KB Output is correct
51 Correct 243 ms 34752 KB Output is correct
52 Correct 238 ms 35520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 7 ms 7004 KB Output is correct
18 Correct 7 ms 7084 KB Output is correct
19 Correct 7 ms 7004 KB Output is correct
20 Correct 7 ms 7004 KB Output is correct
21 Correct 9 ms 7004 KB Output is correct
22 Correct 7 ms 7004 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 0 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 7 ms 7004 KB Output is correct
30 Correct 7 ms 7004 KB Output is correct
31 Correct 7 ms 7004 KB Output is correct
32 Correct 7 ms 7004 KB Output is correct
33 Correct 7 ms 7132 KB Output is correct
34 Correct 7 ms 7004 KB Output is correct
35 Correct 6 ms 7004 KB Output is correct
36 Correct 6 ms 7000 KB Output is correct
37 Correct 7 ms 7004 KB Output is correct
38 Correct 7 ms 7004 KB Output is correct
39 Correct 7 ms 7004 KB Output is correct
40 Correct 7 ms 7128 KB Output is correct
41 Correct 1 ms 4440 KB Output is correct
42 Correct 7 ms 7124 KB Output is correct
43 Correct 7 ms 7004 KB Output is correct
44 Correct 7 ms 7004 KB Output is correct
45 Correct 7 ms 7004 KB Output is correct
46 Correct 8 ms 7004 KB Output is correct
47 Correct 7 ms 7004 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4440 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 8 ms 7004 KB Output is correct
55 Correct 7 ms 7004 KB Output is correct
56 Correct 8 ms 7004 KB Output is correct
57 Correct 9 ms 7004 KB Output is correct
58 Correct 8 ms 7004 KB Output is correct
59 Correct 7 ms 7004 KB Output is correct
60 Correct 7 ms 7004 KB Output is correct
61 Correct 7 ms 7004 KB Output is correct
62 Correct 7 ms 7004 KB Output is correct
63 Correct 7 ms 7004 KB Output is correct
64 Correct 7 ms 7004 KB Output is correct
65 Correct 7 ms 7124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 212 ms 34780 KB Output is correct
17 Correct 200 ms 35008 KB Output is correct
18 Correct 214 ms 35444 KB Output is correct
19 Correct 199 ms 35712 KB Output is correct
20 Correct 198 ms 36408 KB Output is correct
21 Correct 200 ms 34744 KB Output is correct
22 Correct 210 ms 35868 KB Output is correct
23 Correct 194 ms 36288 KB Output is correct
24 Correct 201 ms 35892 KB Output is correct
25 Correct 196 ms 35072 KB Output is correct
26 Correct 198 ms 34756 KB Output is correct
27 Correct 209 ms 35008 KB Output is correct
28 Correct 200 ms 35760 KB Output is correct
29 Correct 205 ms 34500 KB Output is correct
30 Correct 196 ms 35780 KB Output is correct
31 Correct 213 ms 36360 KB Output is correct
32 Correct 214 ms 34956 KB Output is correct
33 Correct 201 ms 36424 KB Output is correct
34 Correct 204 ms 36408 KB Output is correct
35 Correct 201 ms 34608 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 7 ms 7004 KB Output is correct
38 Correct 7 ms 7084 KB Output is correct
39 Correct 7 ms 7004 KB Output is correct
40 Correct 7 ms 7004 KB Output is correct
41 Correct 9 ms 7004 KB Output is correct
42 Correct 7 ms 7004 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 0 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 7 ms 7004 KB Output is correct
50 Correct 7 ms 7004 KB Output is correct
51 Correct 7 ms 7004 KB Output is correct
52 Correct 7 ms 7004 KB Output is correct
53 Correct 7 ms 7132 KB Output is correct
54 Correct 7 ms 7004 KB Output is correct
55 Correct 6 ms 7004 KB Output is correct
56 Correct 6 ms 7000 KB Output is correct
57 Correct 7 ms 7004 KB Output is correct
58 Correct 7 ms 7004 KB Output is correct
59 Correct 7 ms 7004 KB Output is correct
60 Correct 7 ms 7128 KB Output is correct
61 Correct 1 ms 4440 KB Output is correct
62 Correct 244 ms 35388 KB Output is correct
63 Correct 255 ms 35524 KB Output is correct
64 Correct 270 ms 35524 KB Output is correct
65 Correct 247 ms 35740 KB Output is correct
66 Correct 255 ms 35524 KB Output is correct
67 Correct 257 ms 34504 KB Output is correct
68 Correct 1 ms 4444 KB Output is correct
69 Correct 1 ms 4444 KB Output is correct
70 Correct 1 ms 4444 KB Output is correct
71 Correct 1 ms 4440 KB Output is correct
72 Correct 1 ms 4444 KB Output is correct
73 Correct 1 ms 4444 KB Output is correct
74 Correct 244 ms 35128 KB Output is correct
75 Correct 247 ms 35520 KB Output is correct
76 Correct 244 ms 36032 KB Output is correct
77 Correct 246 ms 34624 KB Output is correct
78 Correct 246 ms 34496 KB Output is correct
79 Correct 212 ms 36420 KB Output is correct
80 Correct 183 ms 35140 KB Output is correct
81 Correct 244 ms 36296 KB Output is correct
82 Correct 188 ms 36032 KB Output is correct
83 Correct 183 ms 36296 KB Output is correct
84 Correct 242 ms 36308 KB Output is correct
85 Correct 247 ms 34496 KB Output is correct
86 Correct 243 ms 34752 KB Output is correct
87 Correct 238 ms 35520 KB Output is correct
88 Correct 1 ms 4440 KB Output is correct
89 Correct 1 ms 4444 KB Output is correct
90 Correct 1 ms 4444 KB Output is correct
91 Correct 1 ms 4444 KB Output is correct
92 Correct 1 ms 4444 KB Output is correct
93 Correct 1 ms 4440 KB Output is correct
94 Correct 1 ms 4444 KB Output is correct
95 Correct 1 ms 4444 KB Output is correct
96 Correct 1 ms 4440 KB Output is correct
97 Correct 1 ms 4444 KB Output is correct
98 Correct 1 ms 4440 KB Output is correct
99 Correct 1 ms 4440 KB Output is correct
100 Correct 1 ms 4444 KB Output is correct
101 Correct 1 ms 4444 KB Output is correct
102 Correct 1 ms 4444 KB Output is correct
103 Correct 1 ms 4440 KB Output is correct
104 Correct 7 ms 7124 KB Output is correct
105 Correct 7 ms 7004 KB Output is correct
106 Correct 7 ms 7004 KB Output is correct
107 Correct 7 ms 7004 KB Output is correct
108 Correct 8 ms 7004 KB Output is correct
109 Correct 7 ms 7004 KB Output is correct
110 Correct 1 ms 4444 KB Output is correct
111 Correct 1 ms 4440 KB Output is correct
112 Correct 1 ms 4444 KB Output is correct
113 Correct 1 ms 4444 KB Output is correct
114 Correct 1 ms 4444 KB Output is correct
115 Correct 1 ms 4444 KB Output is correct
116 Correct 8 ms 7004 KB Output is correct
117 Correct 7 ms 7004 KB Output is correct
118 Correct 8 ms 7004 KB Output is correct
119 Correct 9 ms 7004 KB Output is correct
120 Correct 8 ms 7004 KB Output is correct
121 Correct 7 ms 7004 KB Output is correct
122 Correct 7 ms 7004 KB Output is correct
123 Correct 7 ms 7004 KB Output is correct
124 Correct 7 ms 7004 KB Output is correct
125 Correct 7 ms 7004 KB Output is correct
126 Correct 7 ms 7004 KB Output is correct
127 Correct 7 ms 7124 KB Output is correct
128 Correct 1 ms 4444 KB Output is correct
129 Correct 266 ms 35780 KB Output is correct
130 Correct 267 ms 35124 KB Output is correct
131 Correct 267 ms 35520 KB Output is correct
132 Correct 271 ms 34688 KB Output is correct
133 Correct 293 ms 36828 KB Output is correct
134 Correct 280 ms 35008 KB Output is correct
135 Correct 1 ms 4444 KB Output is correct
136 Correct 1 ms 4444 KB Output is correct
137 Correct 1 ms 4444 KB Output is correct
138 Correct 1 ms 4444 KB Output is correct
139 Correct 1 ms 4444 KB Output is correct
140 Correct 1 ms 4444 KB Output is correct
141 Correct 279 ms 35280 KB Output is correct
142 Correct 268 ms 36292 KB Output is correct
143 Correct 269 ms 35068 KB Output is correct
144 Correct 274 ms 36544 KB Output is correct
145 Correct 281 ms 34612 KB Output is correct
146 Correct 246 ms 35004 KB Output is correct
147 Correct 251 ms 34876 KB Output is correct
148 Correct 241 ms 34496 KB Output is correct
149 Correct 263 ms 36156 KB Output is correct
150 Correct 202 ms 35128 KB Output is correct
151 Correct 197 ms 35264 KB Output is correct
152 Correct 262 ms 34500 KB Output is correct
153 Correct 256 ms 34700 KB Output is correct
154 Correct 255 ms 35264 KB Output is correct
155 Correct 269 ms 35636 KB Output is correct