제출 #715707

#제출 시각아이디문제언어결과실행 시간메모리
715707valerikkLong Distance Coach (JOI17_coach)C++17
71 / 100
2041 ms17044 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]; ll prefc[N]; struct seg { int l, r; ll x, sumcost, mnval; }; ll get(int l, int r, ll x) { ll ret = INF; for (int i = l; i < r; ++i) { ret = min(ret, dp[i] - prefc[i] - x * i); } return ret; } 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); } } prefc[0] = 0; for (int i = 0; i < m; ++i) { prefc[i + 1] = prefc[i] + c[i]; } vector<seg> st; st.push_back({0, 0, -1, 0, INF}); for (int i = 0; i < m; ++i) { dp[i + 1] = dp[i] + cost[i]; if (mn[i] != INF) { while (st.back().x >= mn[i]) { st.pop_back(); } seg kek; kek.l = st.back().r; kek.r = i + 1; kek.x = mn[i]; kek.sumcost = st.back().sumcost + kek.x * (kek.r - kek.l); ll prefcost = st.back().sumcost; kek.mnval = min(st.back().mnval, get(kek.l, kek.r, kek.x) - prefcost + kek.x * kek.l); st.push_back(kek); if (st.back().mnval != INF) { dp[i + 1] = min(dp[i + 1], st.back().mnval + prefc[i + 1] + st.back().sumcost); } } } 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...