Submission #563869

#TimeUsernameProblemLanguageResultExecution timeMemory
563869amunduzbaevLong Distance Coach (JOI17_coach)C++17
71 / 100
2084 ms14284 KiB
#include "bits/stdc++.h" using namespace std; #define ar array #define int long long const int inf = 1e18; const int N = 2e5 + 5; int s[N], d[N], c[N], pref[N], cnt[N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int x, n, m, w, t; cin>>x>>n>>m>>w>>t; for(int i=0;i<n;i++) cin>>s[i]; vector<int> p(m), d_(m), mn(m, x + 1); int tot = 0; for(int i=0;i<m;i++){ cin>>d[i]>>c[i]; p[i] = i; } tot += (x / t + 1) * w; sort(p.begin(), p.end(), [&](int i, int j){ return d[i] < d[j]; }); for(int i=0;i<m;i++){ d_[i] = d[p[i]]; cnt[i] = x / t + (d_[i] < x % t); tot += cnt[i] * w; if(i) pref[i] += pref[i-1], cnt[i] += cnt[i-1]; pref[i] += c[p[i]]; } s[n] = x; for(int i=0;i<=n;i++){ int j = upper_bound(d_.begin(), d_.end(), s[i] % t) - d_.begin(); if(j){ --j; //~ assert(d_[j] != s[i] % t); mn[j] = min(mn[j], s[i]); } } vector<int> dp(m); for(int i=0;i<m;i++){ if(i) dp[i] = dp[i-1]; if(mn[i] > x) continue; int M = mn[i] / t; for(int j=i-1;~j;j--){ dp[i] = min(dp[i], dp[j] + cnt[j] * w - M * j * w - pref[j] - cnt[i] * w + M * i * w + pref[i]); } dp[i] = min(dp[i], -cnt[i] * w + M * (i + 1) * w + pref[i]); } //~ for(int i=0;i<m;i++) cout<<dp[i]<<" "; //~ cout<<"\n"; //~ cout<<dp[m-1]<<"\n"; cout<<tot + dp[m-1]<<"\n"; } /* 166833333456456789 333333209997456789 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...