#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) "[" #x " = " << (x) << "]"
#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}
const int N = 2e5+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;
/*
Erase passenger i:
+ Erase all passenger j that has (D(j) > D(i))
and (D(j) + k * T at some position x that has (S(x) % D > D(i))
+ If there is no position that has (S(x) % D > D(i)) then we can't delete passenger i :c
*/
void solve()
{
ll X; int n,m,W,T; cin >> X >> n >> m >> W >> T;
vector<int> S(n + 2), D(m + 1), C(m + 1);
FOR(i, 1, n) cin >> S[i]; S[n + 1] = X;
FOR(i, 1, m) cin >> D[i] >> C[i];
vector<int> idx(m + 1); iota(all(idx), 0);
sort(1 + all(idx), [&](int x, int y){
return D[x] % T > D[y] % T;
});
ll total = (X / T) + 1;
FOR(i, 1, m)
total += (X / T) + (X % T >= D[i]);
total = total * W;
vector<ll> cost(n + 2), dp(m + 1, 0); // O(n ^ 3) <(")
FOR(i, 1, m){
int x = idx[i];
FOR(j, 1, n + 1){
if(S[j] % T > D[x]){
cost[j] = cost[j] + ((X / T) + (X % T >= D[x]) - (S[j] / T)) * W - C[x];
FOR(k, 1, i - 1){
dp[i] = max(dp[i], dp[k] + cost[j]);
}
}
}
dp[i] = max(dp[i], *max_element(all(cost)));
}
cout << total - *max_element(all(dp)) << "\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
Compilation message (stderr)
coach.cpp: In function 'int main()':
coach.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | freopen(name".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
coach.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen(name".OUT","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |