#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
const int MAXN = 200100, MAXK = 30;
//const ll MOD = 998244353;
const ll INF = 4e18;
const ld PI = asin(1) * 2;
ll x, n, m, w, t;
int s[MAXN];
vector<pair<ll, ll>> tmp;
int firstStop[MAXN];
ll dp[MAXN][2];
ll d[MAXN], c[MAXN];
ll prefC[MAXN];
ll waterDrunk[MAXN];
int main()
{
FAST_IO;
cin >> x >> n >> m >> w >> t;
FOR(i, 1, n) cin >> s[i];
sort(s+1, s+n+1);
s[++n] = x; /// the finish
//cout << " n = " << n << " m = " << m << endl;
REP(m) {
// cout << " here " << endl;
ll dd =-1, cc = -1;
cin >> dd >> cc;
//cout << " dd = " << dd << " cc = " << cc << endl;
tmp.pb({dd, cc});
}
sort(tmp.begin(), tmp.end());
tmp.pb({0, 0}); /// driver
m++;
FOR(i, 0, m-1) {
d[i+1] = tmp[i].f;
c[i+1] = tmp[i].s;
}
FOR(i, 1, m) prefC[i] = prefC[i-1] + c[i];
FOR(i, 1, n) {
ll pos = s[i]%t;
ll latest = m;
if (d[1] < pos) {
int le = 1, ri = m-1;
while (le < ri) {
int mid = (le+ri+1)/2;
if (d[mid] < pos) le = mid;
else ri = mid-1;
}
latest = le;
}
if (firstStop[latest] == 0) {
firstStop[latest] = i;
}
waterDrunk[i] = (s[i]-1) / t;
waterDrunk[i] *= m;
waterDrunk[i]++;
if(latest < m) waterDrunk[i] += latest;
waterDrunk[i] *= w;
//cout << " i = " << i << " s="<< s[i] << " waterDrunk = " << waterDrunk[i] << " latest = " << latest << endl;
}
//FOR(i, 1, m) cout << " i = " << i << " firstStop = " << firstStop[i] << endl;
FOR(i, 1, m) {
ll waterThis = (x/t) + (d[i] < (x%t));
waterThis *= w;
dp[i][1] = waterThis + min(dp[i-1][0], dp[i-1][1]);
dp[i][0] = dp[i][1];
if (firstStop[i] == 0) {
// cout << " i = " << i << " d = " << d[i] << " dp0 = dp1 = " << dp[i][1] << " (in cont) " << endl;
continue; /// cannot take since d[i-1] is never an end before a stop
}
FOR(j, 0, i-1) {
ll water = (s[firstStop[i]] - 1) / t;
//water ++;
water *= (ll)(i-j);
water *= w;
ll cur = min(dp[j][0], dp[j][1]) + water + prefC[i] - prefC[j];
dp[i][0] = min(dp[i][0], cur);
//cout << " i = " << i << " j = " << j << " cur = " << cur << " water = " << water << endl;
}
//cout << " i = " << i << " d = " << d[i] << " dp0 = " << dp[i][0] << " dp1 = " << dp[i][1] << endl;
}
cout << dp[m][1] << "\n";
return 0;
}
/*
1000000000000 1 1 1000000 6
999999259244
1 123456789
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |