제출 #1191552

#제출 시각아이디문제언어결과실행 시간메모리
1191552NAMINLong Distance Coach (JOI17_coach)C++20
71 / 100
2093 ms8232 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++){ pref[i] = pref[i-1]+passager[i-1].c; } vector<ll> dp(M+1,1e18); dp[M] = 0; for(int i=M-1;i>=0;i--){ ll D = passager[i].d,C = passager[i].c; dp[i] = dp[i+1]+((X-D)/T+1)*W; for(int j=0;j<=N;j++){ 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(); dp[i] = min(dp[last+1]+(pref[last+1]-pref[i])+(last-i+1)*((S[j]-D)/T)*W ,dp[i]); } } } cout << dp[0] + ((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...