제출 #1187460

#제출 시각아이디문제언어결과실행 시간메모리
1187460Ahmed_KaanicheLong Distance Coach (JOI17_coach)C++17
46 / 100
2095 ms328 KiB
#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back


int main() {
    //the booster of input and output :
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    //the body :
    ll x, n, m, w, t;
    cin >> x >> n >> m >> w >> t;
    vector<ll> stn(n + 1);
    vector<pair<ll, ll>> psg(m);
    vector<ll> prft(n + 1, 0);
    vector<ll> dp(m, 0);
    
    for (int i = 0; i < n; ++i) {
        cin >> stn[i];
    }
    stn[n] = x;
    for (int i = 0; i < m; ++i) {
        cin >> psg[i].fi >> psg[i].se;
    }
    sort(psg.begin(), psg.end(),greater<>());
    
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (psg[i].fi < stn[j] % t) {
                prft[j] += (x / t - stn[j] / t + (psg[i].fi < x % t)) * w - psg[i].se;
                for (int k = 0; k < i; ++k) {
                    if (psg[k].fi > stn[j] % t)
                        dp[i] = max(dp[i], dp[k] + prft[j]);
                }
            }
        }
        dp[i] = max(dp[i], *max_element(prft.begin(), prft.end()));
    }
    
    ll total = w + (x / t) * (m + 1) * w;
    for (int i = 0; i < m; ++i) {
        if (psg[i].fi < x % t)
            total += w;
    }
    cout << total - *max_element(dp.begin(), dp.end()) << endl;
//    for (int i = 0; i < m; ++i) {
//        cout << dp[i] << ' ';
//    }
//    cout << endl;
    
    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...