Submission #563790

#TimeUsernameProblemLanguageResultExecution timeMemory
563790amunduzbaevLong Distance Coach (JOI17_coach)C++17
0 / 100
1 ms340 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, res; 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; res = tot; 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]); } } for(int i=0;i<m;i++){ 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]]; res = min(res, tot + cur); } } cout<<res<<"\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...