Submission #939308

#TimeUsernameProblemLanguageResultExecution timeMemory
939308boris_mihovTreatment Project (JOI20_treatment)C++17
0 / 100
3053 ms5816 KiB
#include <algorithm> #include <iostream> #include <numeric> #include <cassert> #include <vector> typedef long long llong; const int MAXN = 100000 + 10; const llong INF = 1e18; int n, m; struct Interval { int t, l, r, c; friend bool operator < (const Interval &a, const Interval &b) { return a.r < b.r; } }; Interval a[MAXN]; llong dp[MAXN]; void solve() { std::sort(a + 1, a + 1 + n); for (int i = n ; i >= 1 ; --i) { if (a[i].r == m) { dp[i] = a[i].c; } else { dp[i] = INF; } for (int j = i + 1 ; j <= n ; ++j) { if (a[i].r - a[j].l + 1 >= abs(a[i].t - a[j].t)) { dp[i] = std::min(dp[i], dp[j] + a[i].c); } } // std::cout << "dp: " } llong ans = INF; for (int i = 1 ; i <= n ; ++i) { if (a[i].l == 1) { ans = std::min(ans, dp[i]); } } if (ans == INF) std::cout << -1 << '\n'; else std::cout << ans << '\n'; } void input() { std::cin >> m >> n; for (int i = 1 ; i <= n ; ++i) { std::cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c; } } void fastIOI() { std::ios_base :: sync_with_stdio(0); std::cout.tie(nullptr); std::cin.tie(nullptr); } int main() { fastIOI(); input(); solve(); 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...