Submission #563817

#TimeUsernameProblemLanguageResultExecution timeMemory
563817amunduzbaevLong Distance Coach (JOI17_coach)C++17
71 / 100
2068 ms16968 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]; 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 + (d[i] < x % t)) * w; } 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]]; 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 = inf, cur = 0; for(int j=i;~j;j--){ M = min(M, mn[j]); cur = cur - (x / t + (d_[j] < x % t) - M / t) * w + c[p[j]]; dp[i] = min(dp[i], (j ? dp[j-1] : 0) + cur); } } //~ 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...