This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | 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... |