Submission #958023

#TimeUsernameProblemLanguageResultExecution timeMemory
958023Soumya1Long Distance Coach (JOI17_coach)C++17
71 / 100
2049 ms16152 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll inf = 1e18; void testCase() { ll n, x, m, w, t; cin >> x >> n >> m >> w >> t; vector<ll> s(n + 2); for (int i = 1; i <= n; i++) cin >> s[i]; s[n + 1] = x; vector<ll> c(m + 1), d(m + 1); for (int i = 1; i <= m; i++) cin >> d[i] >> c[i]; vector<int> ord(m + 1); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int i, int j) { return d[i] < d[j]; }); { auto cc = c, dd = d; for (int i = 0; i <= m; i++) { cc[i] = c[ord[i]]; dd[i] = d[ord[i]]; } c = cc, d = dd; } vector<ll> mn(m + 1, inf); for (int i = 1; i <= n + 1; i++) { ll x = s[i] % t; if (!x) continue; int j = lower_bound(d.begin(), d.end(), x) - d.begin() - 1; mn[j] = min(mn[j], s[i] / t); } vector<ll> sum(m + 1); for (int i = 1; i <= m; i++) sum[i] = sum[i - 1] + c[i]; vector<ll> dp(m + 1, inf); dp[0] = (x / t + 1) * w; for (int i = 1; i <= m; i++) { dp[i] = dp[i - 1] + ((x - d[i]) / t + 1) * w; if (mn[i] == inf) continue; for (int j = 0; j < i; j++) { dp[i] = min(dp[i], dp[j] + (i - j) * mn[i] * w + sum[i] - sum[j]); } } cout << dp[m] << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); testCase(); 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...