# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
798749 | 2023-07-31T03:10:58 Z | NeroZein | Roller Coaster Railroad (IOI16_railroad) | C++17 | 0 ms | 0 KB |
#include "bits/stdc++.h" using namespace std; const long long INF = 1e18; int main(){ int n, c; cin >> n >> c; vector<int> s(n), t(n); for (int i = 0; i < n; ++i) { cin >> s[i] >> t[i]; } vector<vector<long long>> dp(1 << n, vector<long long> (n, INF)); for (int i = 0; i < n; ++i) { dp[1 << i][i] = 0; } for (int msk = 1; msk < (1 << n); ++msk) { for (int i = 0; i < n; ++i) { if (!(msk >> i & 1)) continue; for (int j = 0; j < n; ++j) { if (msk >> j & 1) continue; dp[msk | (1 << j)][j] = min(dp[msk | (1 << j)][j], dp[msk][i] + max(0, t[i] - s[j])); } } } long long ans = INF; for (int i = 0; i < n; ++i) { ans = min(ans, dp[(1 << n) - 1][i]); } cout << ans << '\n'; return 0; }