Submission #171362

#TimeUsernameProblemLanguageResultExecution timeMemory
171362ho94949Long Distance Coach (JOI17_coach)C++17
0 / 100
4 ms1916 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 202020; long long X, N, M, W, T; long long S[MAXN]; long long D[MAXN], C[MAXN]; // used water before kickout long long nw[MAXN]; //1~(i-1) customer minimum value when ith person do not kicked // -(C_1+...+C_i)+ WV[i] customer's required value. long long DP[MAXN]; // drank water of ith customer if none was kicked long long WV[MAXN]; int pv[MAXN]; long long do_dp() { DP[0] = 0; for(int i=1; i<=M+1; ++i) { DP[i] = DP[i-1]; // not kicking (i-1)th customer if(nw[i] != -1) // if can start kicking strategy, { for(int j=i-2; j>=0; --j) //not kicking jth customer, kicking all DP[i] = min(DP[i], DP[j]+(i-j-1)*nw[i]); } if(pv[i] != 0) //kick through pv player and let what they want. { //cout << "!" << i << " " << pv[i] << endl; DP[i] = min(DP[i], DP[pv[i]] - WV[pv[i]] +C[pv[i]] + (i-pv[i])*nw[i]); } DP[i] += -C[i] + WV[i]; //printf("%d %lld %lld\n", i, nw[i], DP[i]); } long long ans = DP[M+1]; //basic DP value; //we remove C_1...C_N for(int i=1; i<=M; ++i) ans += C[i]; // WV[N+1] is defined as 0 // we should add bus drivers' cost ans += W*(1+X/T); return ans; } int main() { cin >> X >> N >> M >> W >> T; for(int i=0; i<N; ++i) cin >> S[i]; vector<pair<long long, long long> > VDC; for(int i=0; i<M; ++i) { long long d, c; cin >> d >> c; VDC.emplace_back(d, c); } sort(VDC.begin(), VDC.end()); for(int i=1; i<=M; ++i) { tie(D[i], C[i]) = VDC[i-1]; WV[i] = W*(1+(X-D[i])/T); //printf("%d: %lld %lld\n", i, WV[i], C[i]); } S[N] = X; sort(S, S+N+1); memset(nw, -1, sizeof nw); for(int i=0; i<=N; ++i) { long long kickout_water = W*(S[i]/T); int kick_index = lower_bound(D+1, D+1+M, S[i]%T) - D; //printf("%lld %d\n", kickout_water, kick_index); // we will decide whether kick 1~kick_index if(kick_index == 1) continue; if(nw[kick_index] != -1) continue; nw[kick_index] = kickout_water; } int pindex = 0; for(int i=1; i<=M+1; ++i) { if(nw[i] != -1) { pv[i] = pindex; pindex = i; } } printf("%lld\n", do_dp()); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...