#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define range(i, a, b) for (ll i = a; i < b; i++)
#define all(x) begin(x), end(x)
#define INF (1ll << 60)
struct TPos {
ll l, r, c, w;
};
ll m, n;
vector<TPos> arr;
ll check(ll i, ll l, ll r, ll cnt) {
if (l == 1 && r == n) return cnt;
if (!i) return INF;
ll ans = INF;
if (l <= arr[i - 1].c && arr[i - 1].c <= r) {
ans = check(i - 1, min(l, arr[i - 1].l), max(r, arr[i - 1].r), cnt + arr[i - 1].w);
}
ans = min(ans, check(i - 1, l, r, cnt));
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> m >> n;
arr.resize(m);
ll ans = INF;
range(i, 0, m) {
cin >> arr[i].l >> arr[i].r >> arr[i].c >> arr[i].w;
ans = min(check(i, arr[i].l, arr[i].r, arr[i].w), ans);
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |