#include<bits/stdc++.h>
using namespace std;
#define foru(i,a,b) for(int i=(a); i<=(b); ++i)
#define ford(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define bit(s,i) (((s)>>(i))&1)
#define ii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define eb emplace_back
#define ll long long
#define _ << " " <<
template <class X, class Y> bool maxi(X &x, Y y){return x<y?x=y,true:false;}
template <class X, class Y> bool mini(X &x, Y y){return x>y?x=y,true:false;}
const int N=2e5+5;
ll x,s[N],prc[N],dp[N];
int n,m,w,t,minTim[N];
ii pas[N]; /// {time, cost}
struct Line {
ll a, b;
Line() {}
Line(ll a_, ll b_) { a = a_, b = b_; }
ll operator()(ll x) const {
return a*x+b;
}
};
struct seg {
ll l, r, mid; Line val = Line(0, 1e19);
seg() {}
seg(ll l_, ll r_) { l = l_, r = r_, mid = (l + r) / 2; }
seg *lc = NULL, *rc = NULL;
void newNode() {
if (l + 1 == r || lc != NULL) return;
lc = new seg(l, mid); rc = new seg(mid, r);
}
void add(Line k) {
if (k(mid) < val(mid)) swap(k, val);
if (l + 1 == r) return;
newNode();
if (k.a > val.a) lc->add(k);
else rc->add(k);
}
ll get(ll x) {
if (l + 1 == r || lc == NULL) return val(x);
if (x < mid) return min(val(x), lc->get(x));
else return min(val(x), rc->get(x));
}
} st(0,1e12);
void add(int x){
st.add(Line(-1LL*w*x,dp[x]-prc[x]));
}
void solve(){
cin>>x>>n>>m>>w>>t;
foru(i,1,n) cin>>s[i];
foru(i,1,m) cin>>pas[i].fi>>pas[i].se;
sort(pas+1, pas+1+m);
s[++n]=x;
memset(minTim,-1,sizeof(minTim));
foru(i,1,n){
int j=lower_bound(pas+1, pas+1+m, ii(s[i]%t, 0))-pas-1;
if(minTim[j]==-1) minTim[j]=s[i]/t;
else mini(minTim[j], s[i]/t);
}
foru(i,1,m) prc[i]=prc[i-1]+pas[i].se;
memset(dp,0x3f,sizeof(dp));
dp[0]=1LL*(x/t+1)*w; add(0);
foru(i,1,m){
if(minTim[i]!=-1){
dp[i]=st.get(minTim[i])+prc[i]+1LL*minTim[i]*w*i;
}
mini(dp[i],dp[i-1]+1LL*((x-pas[i].fi)/t+1)*w);
add(i);
}
cout<<dp[m]<<'\n';
}
int32_t main(){
#define task "test"
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin.tie(0)->sync_with_stdio(0);
int tc=1; //cin>>tc;
rep(t,tc){
solve();
}
}
Compilation message (stderr)
coach.cpp:38:38: warning: overflow in conversion from 'double' to 'long long int' changes value from '1.0e+19' to '9223372036854775807' [-Woverflow]
38 | ll l, r, mid; Line val = Line(0, 1e19);
| ^~~~
coach.cpp: In function 'int32_t main()':
coach.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
coach.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | freopen(task".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... |