#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pii;
#define f first
#define s second
#define mp make_pair
int x,n,m,w,t;
int kp[200005],dp[200005];
int dea[200005];
pii ppl[200005];
inline int calc(int dj,int cur_time){
return ((cur_time/t) + (dj<=(cur_time%t)?1:0))*w;
}
vector<pair<int,pii> >cht;
int inter(pii a,pii b){
return (b.s-a.s)/(a.f-b.f);
}
void add_line(int m,int c){//strictly decreasing gradients...
pii ll=mp(m,c);
while(cht.size()>1 && inter(ll,cht.back().s)<=cht[cht.size()-2].f){
cht.pop_back();
}
if(cht.size()>0)cht.back().f=inter(cht.back().s,ll);
cht.emplace_back(LLONG_MAX,ll);
}
int query(int x){
// int ans=1e15;
// for(auto ll:cht){
// cout<<ll.f<<'\t'<<ll.s.f<<' '<<ll.s.s<<'\n';
// ans=min(ans,(x*ll.s.f)+ll.s.s);
// }
// return ans;
pii ll=(upper_bound(cht.begin(),cht.end(),mp(x,mp(LLONG_MAX,LLONG_MAX))))->s;
return (x*ll.f)+ll.s;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>x>>n>>m>>w>>t;
for(int i=0;i<n;i++){//"break points"
cin>>kp[i];
}
kp[n++]=x;
for(int i=1;i<=m;i++){//the ppl...
cin>>ppl[i].f>>ppl[i].s;//d_j, refund cost
}
ppl[0]=mp(0,0);//driver...
sort(ppl,ppl+m+1);
//prefix sum refund costs
for(int i=1;i<=m;i++){
ppl[i].s+=ppl[i-1].s;
}
for(int i=0;i<n;i++){
int it=upper_bound(ppl,ppl+m+1,mp(kp[i]%t,LLONG_MAX))-ppl-1;
if(dea[it]==0)dea[it]=kp[i];
else dea[it]=min(dea[it],kp[i]);
}
dp[0]=calc(0,x);
add_line(0,dp[0]);
for(int i=1;i<=m;i++){
//cout<<ppl[i].s<<'\n';
int val=dp[i-1]+calc(ppl[i].f,x);//if we don't refund...
if(dea[i]>0){
// for(int j=0;j<i;j++){
// val=min(val,dp[j]+ppl[i].s-ppl[j].s+((i-j)*(calc(ppl[i].f,dea[i]-t)) ));
// }
int x=calc(ppl[i].f,dea[i]-t);
val=min(val,ppl[i].s+(i*x)+query(x) );
}
dp[i]=val;
add_line(-i,dp[i]-ppl[i].s);
// cout<<i<<' '<<dp[i]<<'\n';
}
cout<<dp[m];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
2 ms |
332 KB |
Output is correct |
41 |
Correct |
2 ms |
348 KB |
Output is correct |
42 |
Correct |
2 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
2 ms |
332 KB |
Output is correct |
45 |
Correct |
2 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
460 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
2 ms |
332 KB |
Output is correct |
49 |
Correct |
2 ms |
332 KB |
Output is correct |
50 |
Correct |
2 ms |
332 KB |
Output is correct |
51 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
2 ms |
332 KB |
Output is correct |
41 |
Correct |
2 ms |
348 KB |
Output is correct |
42 |
Correct |
2 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
2 ms |
332 KB |
Output is correct |
45 |
Correct |
2 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
460 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
2 ms |
332 KB |
Output is correct |
49 |
Correct |
2 ms |
332 KB |
Output is correct |
50 |
Correct |
2 ms |
332 KB |
Output is correct |
51 |
Correct |
2 ms |
332 KB |
Output is correct |
52 |
Correct |
153 ms |
8188 KB |
Output is correct |
53 |
Correct |
115 ms |
13868 KB |
Output is correct |
54 |
Correct |
145 ms |
12968 KB |
Output is correct |
55 |
Correct |
145 ms |
13112 KB |
Output is correct |
56 |
Correct |
146 ms |
13464 KB |
Output is correct |
57 |
Correct |
144 ms |
13168 KB |
Output is correct |
58 |
Correct |
178 ms |
13796 KB |
Output is correct |
59 |
Correct |
145 ms |
13180 KB |
Output is correct |
60 |
Correct |
143 ms |
12996 KB |
Output is correct |
61 |
Correct |
150 ms |
13092 KB |
Output is correct |
62 |
Correct |
151 ms |
13188 KB |
Output is correct |
63 |
Correct |
101 ms |
17896 KB |
Output is correct |
64 |
Correct |
111 ms |
12316 KB |
Output is correct |
65 |
Correct |
120 ms |
13796 KB |
Output is correct |
66 |
Correct |
116 ms |
13836 KB |
Output is correct |
67 |
Correct |
116 ms |
13764 KB |
Output is correct |
68 |
Correct |
116 ms |
13888 KB |
Output is correct |
69 |
Correct |
155 ms |
13572 KB |
Output is correct |
70 |
Correct |
156 ms |
13584 KB |
Output is correct |
71 |
Correct |
169 ms |
13556 KB |
Output is correct |
72 |
Correct |
153 ms |
13588 KB |
Output is correct |
73 |
Correct |
161 ms |
13608 KB |
Output is correct |
74 |
Correct |
160 ms |
13636 KB |
Output is correct |
75 |
Correct |
149 ms |
13720 KB |
Output is correct |
76 |
Correct |
152 ms |
13800 KB |
Output is correct |
77 |
Correct |
171 ms |
13480 KB |
Output is correct |
78 |
Correct |
155 ms |
13768 KB |
Output is correct |
79 |
Correct |
150 ms |
13316 KB |
Output is correct |
80 |
Correct |
164 ms |
13332 KB |
Output is correct |