Submission #1191549

#TimeUsernameProblemLanguageResultExecution timeMemory
1191549NAMINLong Distance Coach (JOI17_coach)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> #define endl "\n" #define ll long long using namespace std; struct pass{ ll d,c; bool operator<(const pass p)const{ if(d == p.d) return c < p.c; return d < p.d; } }; void solve(){ ll X,N,M,W,T; cin >> X >> N >> M >> W >> T; vector<ll> S(N); for(int i=0;i<N;i++) cin >> S[i]; S.push_back(X); vector<pass> passager(M); for(int i=0;i<M;i++){ cin >> passager[i].d >> passager[i].c; } sort(passager.begin(),passager.end()); sort(S.begin(),S.end()); vector<ll> pref(M+1,0); for(int i=1;i<=M;i++){ //cout << passager[i-1].d <<' '; pref[i] = pref[i-1]+passager[i-1].c; } //cout << endl; vector<vector<ll>> dp(M+1,vector<ll>(N+1,1e18)); dp[M][N] = 0; for(int i=M-1;i>=0;i--){ ll D = passager[i].d,C = passager[i].c; for(int j=0;j<=N;j++){ dp[i][j] = dp[i+1][N] + ((X-D)/T+1) * W; if(S[j]%T > D){ pass p = {S[j]%T,-1LL}; auto it = upper_bound(passager.begin(),passager.end(),p); assert(it != passager.begin()); it--; int last = it-passager.begin(); /*cout << "i : " << i << endl; cout << "S[j] = " << S[j]%T << endl; cout << "last : " << i << ' ' << last << endl; cout << "pref :" << pref[last+1]-pref[i] << endl;*/ dp[i][j] = min(dp[last+1][N] + (pref[last+1]-pref[i]) + (last-i+1)*(S[j]-D)/T * W, dp[i][j]); } if(j) dp[i][j] = min(dp[i][j-1],dp[i][j]); } } /*for(int i=0;i<=M;i++){ for(int j=0;j<=N;j++){ cout << dp[i][j] << ' '; } cout << endl; }*/ cout << dp[0][N]+(X/T+1) * W << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } 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...