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;
int M, N;
array<int, 4> A[100005];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> M >> N;
for(int l = 0; l < M; l++) {
cin >> A[l][0] >> A[l][1] >> A[l][2] >> A[l][3];
}
vector<int> L(M, 1e9 + 7);
vector<int> R(M, 1e9 + 7);
for(int l = 0; l < M; l++) {
if(A[l][0] == 1)
L[l] = A[l][3];
else {
for(int i = 0; i < l; i++) {
if(A[i][2] >= A[l][0] && A[i][2] <= A[l][1]) {
L[l] = min(L[l], L[i] + A[l][3]);
}
}
}
if(A[l][1] == N)
R[l] = A[l][3];
else {
for(int i = 0; i < l; i++) {
if(A[i][2] >= A[l][0] && A[i][2] <= A[l][1]) {
R[l] = min(R[l], R[i] + A[l][3]);
}
}
}
}
int res = 1e9 + 7;
for(int l = 0; l < M; l++)
res = min(res, L[l] + R[l] - A[l][3]);
cout << (res == 1e9 + 7 ? -1 : res) << "\n";
}
# | 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... |