Submission #908853

#TimeUsernameProblemLanguageResultExecution timeMemory
908853vjudge1Pinball (JOI14_pinball)C++17
0 / 100
1 ms600 KiB
#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 && (arr[i - 1].l < l || r < arr[i - 1].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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...