#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];
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, res;
for(int i=0;i<m;i++){
cin>>d[i]>>c[i];
p[i] = i;
tot += ((x / t) + (d[i] < x % t)) * w;
}
tot += (x / t + 1) * w;
res = tot;
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]];
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;
mn[j] = min(mn[j], s[i]);
}
}
for(int i=0;i<m;i++){
if(mn[i] > x) continue;
int M = inf, cur = 0;
for(int j=i;~j;j--){
M = min(M, mn[j]);
cur = cur - (x / t + (d_[j] < x % t) - M / t) * w + c[p[j]];
res = min(res, tot + cur);
}
}
cout<<res<<"\n";
}
/*
166833333456456789
333333209997456789
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |