#include <bits/stdc++.h>
// #define int long long
using namespace std;
signed main(){
int m, n;
cin>> m >> n;
pair<pair<int, int>, pair<int, int>> arr[m];
for(int i = 0; i < m;i ++) {
cin >> arr[i].first.first >> arr[i].first.second >> arr[i].second.first >> arr[i].second.second;
}
// int best[m][m]; // fist is arr[i].first.first, second is arr[i].second.second
map<pair<int, int>, int> best;
// for(int i = 0; i < m; i++) {
// for(int j = 0; j < m; j++) {
// best[i][j] = LONG_LONG_MAX;
// }
// }
for(int i = m-1; i >= 0; i--) {
if(!best.contains({arr[i].first.first, arr[i].first.second})) {
best[{arr[i].first.first,arr[i].first.second}] = arr[i].second.second;
}else {
best[{arr[i].first.first, arr[i].first.second}] = min(best[{arr[i].first.first, arr[i].first.second}], arr[i].second.second);
}
for(pair<pair<int, int>, int> j : best) {
if(arr[i].second.first >= j.first.first && arr[i].second.first <= j.first.second) {
int left = min(j.first.first, arr[i].first.first);
int right = max(j.first.second, arr[i].first.second);
if(!best.contains({left, right})) {
best[{left, right}] = j.second + arr[i].second.second;
}else {
best[{left, right}] = min(best[{left, right}], j.second + arr[i].second.second);
}
}
}
}
if(!best.contains({1, n})) {
cout<<-1<<'\n';
}else {
cout<<best[{1, n}]<<'\n';
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |