# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
754959 | MilosMilutinovic | Treatment Project (JOI20_treatment) | C++14 | 3040 ms | 3020 KiB |
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
const int N = 1e5 + 10;
const ll inf = 0x3f3f3f3f3f3f3f3f;
int n, m, t[N], l[N], r[N], c[N], order[N];
ll dp[N];
bool cmp(int i, int j) { return l[i] < l[j]; }
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d%d%d", &t[i], &l[i], &r[i], &c[i]);
order[i] = i;
dp[i] = inf;
}
sort(order + 1, order + m + 1, cmp);
for (int _i = 1; _i <= m; _i++) {
int i = order[_i];
if (l[i] == 1) {
dp[i] = c[i];
continue;
}
for (int _j = 1; _j < _i; _j++) {
int j = order[_j];
if (min(r[j], r[j] - abs(t[i] - t[j])) >= l[i] - 1)
dp[i] = min(dp[i], dp[j] + c[i]);
}
}
// for (int i = 1; i <= m; i++)
// printf("%lld\n", dp[i]);
ll ans = inf;
for (int i = 1; i <= m; i++)
if (r[order[i]] == n)
ans = min(ans, dp[order[i]]);
if (ans == inf)
printf("%d", -1);
else
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | 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... |