#include <bits/stdc++.h>
#define long long long
using namespace std;
const int N = 3e5+5;
void update(long t[], int x, long k) {
x += N;
for(t[x] = min(t[x], k); x != 1; x >>= 1)
t[x >> 1] = min(t[x], t[x ^ 1]);
}
long query(long t[], int l, int r) {
long ret = 1e18;
for(l += N, r += N + 1; l < r; l >>= 1, r >>= 1) {
if(l & 1) ret = min(ret, t[l++]);
if(r & 1) ret = min(ret, t[--r]);
}
return ret;
}
int n, m;
int A[N], B[N], C[N], D[N];
vector<int> coord;
long t1[N << 1], t2[N << 1];
int get(int x) { return lower_bound(coord.begin(), coord.end(), x) - coord.begin() + 1; }
int main() {
fill_n(t1, N << 1, 1e18), fill_n(t2, N << 1, 1e18);
scanf("%d %d", &n, &m);
coord.emplace_back(1), coord.emplace_back(m);
for(int i = 1; i <= n; i++) {
scanf("%d %d %d %d", A + i, B + i, C + i, D + i);
coord.emplace_back(A[i]), coord.emplace_back(B[i]);
coord.emplace_back(C[i]);
}
sort(coord.begin(), coord.end());
coord.resize(unique(coord.begin(), coord.end()) - coord.begin());
long ans = 1e18;
update(t1, 1, 0), update(t2, coord.size(), 0);
for(int i = 1; i <= n; i++) {
long pre = query(t1, get(A[i]), get(B[i]));
long suf = query(t2, get(A[i]), get(B[i]));
ans = min(ans, pre + suf + D[i]);
update(t1, get(C[i]), pre + D[i]), update(t2, get(C[i]), suf + D[i]);
}
if(ans == 1e18) printf("-1\n");
else printf("%lld\n", ans);
return 0;
}
Compilation message
pinball.cpp: In function 'int main()':
pinball.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
pinball.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", A + i, B + i, C + i, D + i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9728 KB |
Output is correct |
2 |
Correct |
9 ms |
9728 KB |
Output is correct |
3 |
Correct |
9 ms |
9728 KB |
Output is correct |
4 |
Correct |
9 ms |
9728 KB |
Output is correct |
5 |
Correct |
9 ms |
9728 KB |
Output is correct |
6 |
Correct |
9 ms |
9728 KB |
Output is correct |
7 |
Correct |
9 ms |
9728 KB |
Output is correct |
8 |
Correct |
9 ms |
9728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9728 KB |
Output is correct |
2 |
Correct |
9 ms |
9728 KB |
Output is correct |
3 |
Correct |
9 ms |
9728 KB |
Output is correct |
4 |
Correct |
9 ms |
9728 KB |
Output is correct |
5 |
Correct |
9 ms |
9728 KB |
Output is correct |
6 |
Correct |
9 ms |
9728 KB |
Output is correct |
7 |
Correct |
9 ms |
9728 KB |
Output is correct |
8 |
Correct |
9 ms |
9728 KB |
Output is correct |
9 |
Correct |
10 ms |
9728 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
11 |
Correct |
10 ms |
9728 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
11 ms |
9728 KB |
Output is correct |
14 |
Correct |
9 ms |
9728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9728 KB |
Output is correct |
2 |
Correct |
9 ms |
9728 KB |
Output is correct |
3 |
Correct |
9 ms |
9728 KB |
Output is correct |
4 |
Correct |
9 ms |
9728 KB |
Output is correct |
5 |
Correct |
9 ms |
9728 KB |
Output is correct |
6 |
Correct |
9 ms |
9728 KB |
Output is correct |
7 |
Correct |
9 ms |
9728 KB |
Output is correct |
8 |
Correct |
9 ms |
9728 KB |
Output is correct |
9 |
Correct |
10 ms |
9728 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
11 |
Correct |
10 ms |
9728 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
11 ms |
9728 KB |
Output is correct |
14 |
Correct |
9 ms |
9728 KB |
Output is correct |
15 |
Correct |
9 ms |
9728 KB |
Output is correct |
16 |
Correct |
10 ms |
9728 KB |
Output is correct |
17 |
Correct |
10 ms |
9856 KB |
Output is correct |
18 |
Correct |
14 ms |
9984 KB |
Output is correct |
19 |
Correct |
11 ms |
9856 KB |
Output is correct |
20 |
Correct |
11 ms |
9856 KB |
Output is correct |
21 |
Correct |
10 ms |
9856 KB |
Output is correct |
22 |
Correct |
11 ms |
9856 KB |
Output is correct |
23 |
Correct |
10 ms |
9856 KB |
Output is correct |
24 |
Correct |
11 ms |
9856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9728 KB |
Output is correct |
2 |
Correct |
9 ms |
9728 KB |
Output is correct |
3 |
Correct |
9 ms |
9728 KB |
Output is correct |
4 |
Correct |
9 ms |
9728 KB |
Output is correct |
5 |
Correct |
9 ms |
9728 KB |
Output is correct |
6 |
Correct |
9 ms |
9728 KB |
Output is correct |
7 |
Correct |
9 ms |
9728 KB |
Output is correct |
8 |
Correct |
9 ms |
9728 KB |
Output is correct |
9 |
Correct |
10 ms |
9728 KB |
Output is correct |
10 |
Correct |
9 ms |
9728 KB |
Output is correct |
11 |
Correct |
10 ms |
9728 KB |
Output is correct |
12 |
Correct |
10 ms |
9728 KB |
Output is correct |
13 |
Correct |
11 ms |
9728 KB |
Output is correct |
14 |
Correct |
9 ms |
9728 KB |
Output is correct |
15 |
Correct |
9 ms |
9728 KB |
Output is correct |
16 |
Correct |
10 ms |
9728 KB |
Output is correct |
17 |
Correct |
10 ms |
9856 KB |
Output is correct |
18 |
Correct |
14 ms |
9984 KB |
Output is correct |
19 |
Correct |
11 ms |
9856 KB |
Output is correct |
20 |
Correct |
11 ms |
9856 KB |
Output is correct |
21 |
Correct |
10 ms |
9856 KB |
Output is correct |
22 |
Correct |
11 ms |
9856 KB |
Output is correct |
23 |
Correct |
10 ms |
9856 KB |
Output is correct |
24 |
Correct |
11 ms |
9856 KB |
Output is correct |
25 |
Correct |
29 ms |
10496 KB |
Output is correct |
26 |
Correct |
53 ms |
11644 KB |
Output is correct |
27 |
Correct |
137 ms |
14312 KB |
Output is correct |
28 |
Correct |
146 ms |
16616 KB |
Output is correct |
29 |
Correct |
104 ms |
13424 KB |
Output is correct |
30 |
Correct |
180 ms |
16876 KB |
Output is correct |
31 |
Correct |
211 ms |
16872 KB |
Output is correct |
32 |
Correct |
201 ms |
16872 KB |
Output is correct |
33 |
Correct |
33 ms |
11132 KB |
Output is correct |
34 |
Correct |
98 ms |
13552 KB |
Output is correct |
35 |
Correct |
135 ms |
16876 KB |
Output is correct |
36 |
Correct |
232 ms |
16876 KB |
Output is correct |
37 |
Correct |
189 ms |
16876 KB |
Output is correct |
38 |
Correct |
180 ms |
16876 KB |
Output is correct |