#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
const int inf = 1e18;
const int N = 2e5 + 5;
int s[N], d[N], c[N], pref[N], cnt[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int x, n, m, w, t; cin>>x>>n>>m>>w>>t;
for(int i=0;i<n;i++) cin>>s[i];
vector<int> p(m), d_(m), mn(m, x + 1);
int tot = 0;
for(int i=0;i<m;i++){
cin>>d[i]>>c[i];
p[i] = i;
tot += cnt[i] * w;
}
tot += (x / t + 1) * w;
sort(p.begin(), p.end(), [&](int i, int j){
return d[i] < d[j];
});
for(int i=0;i<m;i++){
d_[i] = d[p[i]];
cnt[i] = x / t + (d_[i] < x % t);
if(i) pref[i] += pref[i-1], cnt[i] += cnt[i-1];
pref[i] += c[p[i]];
}
s[n] = x;
for(int i=0;i<=n;i++){
int j = upper_bound(d_.begin(), d_.end(), s[i] % t) - d_.begin();
if(j){ --j;
//~ assert(d_[j] != s[i] % t);
mn[j] = min(mn[j], s[i]);
}
}
vector<int> dp(m);
for(int i=0;i<m;i++){
if(i) dp[i] = dp[i-1];
if(mn[i] > x) continue;
int M = mn[i] / t;
for(int j=i-1;~j;j--){
dp[i] = min(dp[i], dp[j] + cnt[j] * w - M * j * w - pref[j] - cnt[i] * w + M * i * w + pref[i]);
}
dp[i] = min(dp[i], -cnt[i] * w + M * i * w + pref[i]);
}
//~ cout<<dp[m-1]<<"\n";
cout<<tot + dp[m-1]<<"\n";
}
/*
166833333456456789
333333209997456789
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |