Submission #715703

#TimeUsernameProblemLanguageResultExecution timeMemory
715703valerikkLong Distance Coach (JOI17_coach)C++17
71 / 100
2066 ms14260 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 7; const ll INF = 2e18; int n, m; ll X, T, W; ll s[N]; ll d[N], c[N]; ll cost[N]; ll mn[N]; ll dp[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> X >> n >> m >> W >> T; for (int i = 0; i < n; ++i) { cin >> s[i]; } sort(s, s + n); s[n++] = X; { vector<pair<ll, ll>> kek(m); for (int i = 0; i < m; ++i) { cin >> kek[i].first >> kek[i].second; } sort(kek.begin(), kek.end()); for (int i = 0; i < m; ++i) { d[i] = kek[i].first; c[i] = kek[i].second; } } for (int i = 0; i < m; ++i) { cost[i] = ((X - d[i]) / T + 1) * W; } for (int i = 0; i < m; ++i) { mn[i] = INF; } for (int i = 0; i < n; ++i) { int ind = lower_bound(d, d + m, s[i] % T) - d - 1; if (ind != -1) { mn[ind] = min(mn[ind], s[i] / T * W); } } for (int i = 0; i < m; ++i) { dp[i + 1] = dp[i] + cost[i]; for (int j = 0; j <= i; ++j) { cost[j] = min(cost[j], mn[i]); } ll sum = 0; for (int j = i; j >= 0; --j) { sum += cost[j] + c[j]; dp[i + 1] = min(dp[i + 1], dp[j] + sum); } } cout << dp[m] + (X / T + 1) * W << "\n"; 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...