#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m;
const int MXN = 1005;
int l[MXN], r[MXN], to[MXN], c[MXN];
int lec[MXN], ric[MXN];
int MXE = LLONG_MAX / 2;
int ans = MXE;
bool can;
signed main() {
cin >> m >> n;
for (int i=1; i<=m; i++) {
cin >> l[i] >> r[i] >> to[i] >> c[i];
}
for (int i=1; i<=m; i++) {
if (l[i] == 1) {
lec[i] = c[i];
}
else {
lec[i] = MXE;
for (int x=1; x<i; x++) {
if (l[i] <= to[x] && to[x] <= r[i]) {
lec[i] = min(lec[i], lec[x] + c[i]);
}
}
}
if (r[i] == n) {
ric[i] = c[i];
}
else {
ric[i] = MXE;
for (int x=1; x<i; x++) {
if (l[i] <= to[x] && to[x] <= r[i]) {
ric[i] = min(ric[i], ric[x] + c[i]);
}
}
}
if (lec[i] == MXE || ric[i] == MXE) continue;
can = true;
ans = min(ans, lec[i] + ric[i] - c[i]);
}
if (can) cout << ans << endl;
else cout << -1 << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
7 ms |
364 KB |
Output is correct |
18 |
Correct |
7 ms |
364 KB |
Output is correct |
19 |
Correct |
7 ms |
364 KB |
Output is correct |
20 |
Correct |
8 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
396 KB |
Output is correct |
22 |
Correct |
6 ms |
364 KB |
Output is correct |
23 |
Correct |
4 ms |
364 KB |
Output is correct |
24 |
Correct |
5 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
7 ms |
364 KB |
Output is correct |
18 |
Correct |
7 ms |
364 KB |
Output is correct |
19 |
Correct |
7 ms |
364 KB |
Output is correct |
20 |
Correct |
8 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
396 KB |
Output is correct |
22 |
Correct |
6 ms |
364 KB |
Output is correct |
23 |
Correct |
4 ms |
364 KB |
Output is correct |
24 |
Correct |
5 ms |
364 KB |
Output is correct |
25 |
Runtime error |
3 ms |
620 KB |
Execution killed with signal 11 |
26 |
Halted |
0 ms |
0 KB |
- |