이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 1e5 + 2;
int64 a[maxn], b[maxn], c[maxn], cost[maxn];
int64 l[maxn], r[maxn]; // l[i] -> min cost sa ajungi in device i incepand de pe coloana 1
// r[i] -> min cost sa ajungi in device i incepand de pe coloana m
int main() {
int n,m;
cin >> n >> m;
for (int i = 0; i < n; i++){
cin >> a[i] >> b[i] >> c[i] >> cost[i];
l[i] = r[i] = 1e18;
}
int64 rs = 1e18;
for (int i = 0; i < n; i++){
if (a[i] == 1) l[i] = cost[i];
if (b[i] == m) r[i] = cost[i];
for (int j = i - 1; j >= 0; j--){
if (a[i] <= c[j] && c[j] <= b[i]) l[i] = min(l[i], l[j] + cost[i]);
if (a[i] <= c[j] && c[j] <= b[i]) r[i] = min(r[i], r[j] + cost[i]);
}
rs = min(rs, l[i] + r[i] - cost[i]);
}
cout << (rs == 1e18 ? -1: rs);
}
# | 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... |