#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <iterator>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int mxn = 100000;
int n, m;
map<int, ll> dpl;
map<int, ll, greater<int>> dpr;
void add(auto &dp, int x, ll y){
auto it = dp.insert({x, y}).f;
it->s = min(it->s, y);
while(it != dp.begin() && (--it)->s >= y) it = dp.erase(it);
if(it != dp.end() && next(++it)->s <= y) dp.erase(it);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
ll ret = !!~-m * inf;
dpl[1] = 0, dpl[m] = inf, dpr[1] = inf, dpr[m] = 0;
for(int i = 0; i < n; i++){
int l, r, x, y;
cin >> l >> r >> x >> y;
ll vl = dpl.lower_bound(l)->s, vr = dpr.lower_bound(r)->s;
ret = min(ret, vl + vr + y);
add(dpl, x, vl + y), add(dpr, x, vr + y);
}
cout << (ret < inf ? ret : -1) << endl;
return 0;
}
Compilation message
pinball.cpp:19:10: warning: use of 'auto' in parameter declaration only available with '-fconcepts'
19 | void add(auto &dp, int x, ll y){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |