#include <bits/stdc++.h>
#define lld long long
#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define Mod 1000000007
using namespace std;
int N,M;
lld X,W,T;
lld a[200002],d[200002],memo[200002],sum[200002];
struct data{
lld d,c;
data(){}
data(lld d,lld c):d(d),c(c){}
bool operator < (const data &cmp) const{
return d < cmp.d;
}
}b[200002];
pll tmp[200002];
struct CHTaaa{
int cr = -1;
lld f(int num,lld x){
return tmp[num].first*x+tmp[num].second;
}
lld ccw(pll x,pll y,pll z){
return (x.first*y.second+y.first*z.second+z.first*x.second)
-(y.first*x.second+z.first*y.second+x.first*z.second);
}
void add(lld x,lld y){
while(cr > 0 && ccw(tmp[cr-1],tmp[cr],pll(x,y)) >= 0) cr--;
cr++;
tmp[cr] = pll(x,y);
}
lld get(lld x){
int l,r;
l = 0; r = cr;
while(l < r){
int m = (l+r)>>1;
if(f(m,x) < f(m+1,x)) r = m;
else l = m+1;
}
return f(l,x);
}
}cht;
lld get(lld x){
return ((X-x)/T+1)*W;
}
int main(){
long long iX,iW,iT;
scanf("%lld %d %d %lld %lld",&iX,&N,&M,&iW,&iT);
X = iX; W = iW; T = iT;
for(int i=1; i<=N; i++){
long long ia;
scanf("%lld",&ia);
a[i] = ia;
}
sort(a+1,a+N+1);
for(int i=1; i<=M; i++){
long long id,ic;
scanf("%lld %lld",&id,&ic);
b[i].d = id; b[i].c = ic;
}
sort(b+1,b+M+1);
a[N+1] = X;
for(int i=1; i<=M; i++){
memo[i] = Linf;
sum[i] = sum[i-1]+b[i].c;
}
for(int i=1; i<=N+1; i++){
int it;
it = lower_bound(b+1,b+M+1,data(a[i]%T,0))-b-1;
memo[it] = min(memo[it],(a[i]/T)*W);
}
d[0] = get(0);
cht.add(0,d[0]);
for(int i=1; i<=M; i++){
d[i] = Linf;
if(memo[i] != Linf){
d[i] = cht.get(memo[i]);
d[i] += sum[i]+memo[i]*i;
}
d[i] = min(d[i],d[i-1]+get(b[i].d));
cht.add(-i,d[i]-sum[i]);
}
long long print = d[M];
printf("%lld\n",print);
return 0;
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:59:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %d %d %lld %lld",&iX,&N,&M,&iW,&iT);
^
coach.cpp:63:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&ia);
^
coach.cpp:69:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&id,&ic);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
14524 KB |
Output is correct |
2 |
Correct |
0 ms |
14524 KB |
Output is correct |
3 |
Correct |
0 ms |
14524 KB |
Output is correct |
4 |
Correct |
0 ms |
14524 KB |
Output is correct |
5 |
Correct |
0 ms |
14524 KB |
Output is correct |
6 |
Correct |
0 ms |
14524 KB |
Output is correct |
7 |
Correct |
0 ms |
14524 KB |
Output is correct |
8 |
Correct |
0 ms |
14524 KB |
Output is correct |
9 |
Correct |
0 ms |
14524 KB |
Output is correct |
10 |
Correct |
0 ms |
14524 KB |
Output is correct |
11 |
Correct |
0 ms |
14524 KB |
Output is correct |
12 |
Correct |
0 ms |
14524 KB |
Output is correct |
13 |
Correct |
0 ms |
14524 KB |
Output is correct |
14 |
Correct |
0 ms |
14524 KB |
Output is correct |
15 |
Correct |
0 ms |
14524 KB |
Output is correct |
16 |
Correct |
0 ms |
14524 KB |
Output is correct |
17 |
Correct |
0 ms |
14524 KB |
Output is correct |
18 |
Correct |
0 ms |
14524 KB |
Output is correct |
19 |
Correct |
0 ms |
14524 KB |
Output is correct |
20 |
Correct |
0 ms |
14524 KB |
Output is correct |
21 |
Correct |
0 ms |
14524 KB |
Output is correct |
22 |
Correct |
0 ms |
14524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
14524 KB |
Output is correct |
2 |
Correct |
0 ms |
14524 KB |
Output is correct |
3 |
Correct |
0 ms |
14524 KB |
Output is correct |
4 |
Correct |
0 ms |
14524 KB |
Output is correct |
5 |
Correct |
0 ms |
14524 KB |
Output is correct |
6 |
Correct |
0 ms |
14524 KB |
Output is correct |
7 |
Correct |
0 ms |
14524 KB |
Output is correct |
8 |
Correct |
0 ms |
14524 KB |
Output is correct |
9 |
Correct |
0 ms |
14524 KB |
Output is correct |
10 |
Correct |
0 ms |
14524 KB |
Output is correct |
11 |
Correct |
0 ms |
14524 KB |
Output is correct |
12 |
Correct |
0 ms |
14524 KB |
Output is correct |
13 |
Correct |
0 ms |
14524 KB |
Output is correct |
14 |
Correct |
0 ms |
14524 KB |
Output is correct |
15 |
Correct |
0 ms |
14524 KB |
Output is correct |
16 |
Correct |
0 ms |
14524 KB |
Output is correct |
17 |
Correct |
0 ms |
14524 KB |
Output is correct |
18 |
Correct |
0 ms |
14524 KB |
Output is correct |
19 |
Correct |
0 ms |
14524 KB |
Output is correct |
20 |
Correct |
0 ms |
14524 KB |
Output is correct |
21 |
Correct |
0 ms |
14524 KB |
Output is correct |
22 |
Correct |
0 ms |
14524 KB |
Output is correct |
23 |
Correct |
0 ms |
14524 KB |
Output is correct |
24 |
Correct |
0 ms |
14524 KB |
Output is correct |
25 |
Correct |
0 ms |
14524 KB |
Output is correct |
26 |
Correct |
0 ms |
14524 KB |
Output is correct |
27 |
Correct |
0 ms |
14524 KB |
Output is correct |
28 |
Correct |
0 ms |
14524 KB |
Output is correct |
29 |
Correct |
0 ms |
14524 KB |
Output is correct |
30 |
Correct |
0 ms |
14524 KB |
Output is correct |
31 |
Correct |
0 ms |
14524 KB |
Output is correct |
32 |
Correct |
0 ms |
14524 KB |
Output is correct |
33 |
Correct |
0 ms |
14524 KB |
Output is correct |
34 |
Correct |
0 ms |
14524 KB |
Output is correct |
35 |
Correct |
0 ms |
14524 KB |
Output is correct |
36 |
Correct |
0 ms |
14524 KB |
Output is correct |
37 |
Correct |
0 ms |
14524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
14524 KB |
Output is correct |
2 |
Correct |
0 ms |
14524 KB |
Output is correct |
3 |
Correct |
0 ms |
14524 KB |
Output is correct |
4 |
Correct |
0 ms |
14524 KB |
Output is correct |
5 |
Correct |
0 ms |
14524 KB |
Output is correct |
6 |
Correct |
0 ms |
14524 KB |
Output is correct |
7 |
Correct |
0 ms |
14524 KB |
Output is correct |
8 |
Correct |
0 ms |
14524 KB |
Output is correct |
9 |
Correct |
0 ms |
14524 KB |
Output is correct |
10 |
Correct |
0 ms |
14524 KB |
Output is correct |
11 |
Correct |
0 ms |
14524 KB |
Output is correct |
12 |
Correct |
0 ms |
14524 KB |
Output is correct |
13 |
Correct |
0 ms |
14524 KB |
Output is correct |
14 |
Correct |
0 ms |
14524 KB |
Output is correct |
15 |
Correct |
0 ms |
14524 KB |
Output is correct |
16 |
Correct |
0 ms |
14524 KB |
Output is correct |
17 |
Correct |
0 ms |
14524 KB |
Output is correct |
18 |
Correct |
0 ms |
14524 KB |
Output is correct |
19 |
Correct |
0 ms |
14524 KB |
Output is correct |
20 |
Correct |
0 ms |
14524 KB |
Output is correct |
21 |
Correct |
0 ms |
14524 KB |
Output is correct |
22 |
Correct |
0 ms |
14524 KB |
Output is correct |
23 |
Correct |
0 ms |
14524 KB |
Output is correct |
24 |
Correct |
0 ms |
14524 KB |
Output is correct |
25 |
Correct |
0 ms |
14524 KB |
Output is correct |
26 |
Correct |
0 ms |
14524 KB |
Output is correct |
27 |
Correct |
0 ms |
14524 KB |
Output is correct |
28 |
Correct |
0 ms |
14524 KB |
Output is correct |
29 |
Correct |
0 ms |
14524 KB |
Output is correct |
30 |
Correct |
0 ms |
14524 KB |
Output is correct |
31 |
Correct |
0 ms |
14524 KB |
Output is correct |
32 |
Correct |
0 ms |
14524 KB |
Output is correct |
33 |
Correct |
0 ms |
14524 KB |
Output is correct |
34 |
Correct |
0 ms |
14524 KB |
Output is correct |
35 |
Correct |
0 ms |
14524 KB |
Output is correct |
36 |
Correct |
0 ms |
14524 KB |
Output is correct |
37 |
Correct |
0 ms |
14524 KB |
Output is correct |
38 |
Correct |
0 ms |
14524 KB |
Output is correct |
39 |
Correct |
0 ms |
14524 KB |
Output is correct |
40 |
Correct |
0 ms |
14524 KB |
Output is correct |
41 |
Correct |
0 ms |
14524 KB |
Output is correct |
42 |
Correct |
0 ms |
14524 KB |
Output is correct |
43 |
Correct |
0 ms |
14524 KB |
Output is correct |
44 |
Correct |
0 ms |
14524 KB |
Output is correct |
45 |
Correct |
0 ms |
14524 KB |
Output is correct |
46 |
Correct |
0 ms |
14524 KB |
Output is correct |
47 |
Correct |
0 ms |
14524 KB |
Output is correct |
48 |
Correct |
0 ms |
14524 KB |
Output is correct |
49 |
Correct |
0 ms |
14524 KB |
Output is correct |
50 |
Correct |
0 ms |
14524 KB |
Output is correct |
51 |
Correct |
0 ms |
14524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
14524 KB |
Output is correct |
2 |
Correct |
0 ms |
14524 KB |
Output is correct |
3 |
Correct |
0 ms |
14524 KB |
Output is correct |
4 |
Correct |
0 ms |
14524 KB |
Output is correct |
5 |
Correct |
0 ms |
14524 KB |
Output is correct |
6 |
Correct |
0 ms |
14524 KB |
Output is correct |
7 |
Correct |
0 ms |
14524 KB |
Output is correct |
8 |
Correct |
0 ms |
14524 KB |
Output is correct |
9 |
Correct |
0 ms |
14524 KB |
Output is correct |
10 |
Correct |
0 ms |
14524 KB |
Output is correct |
11 |
Correct |
0 ms |
14524 KB |
Output is correct |
12 |
Correct |
0 ms |
14524 KB |
Output is correct |
13 |
Correct |
0 ms |
14524 KB |
Output is correct |
14 |
Correct |
0 ms |
14524 KB |
Output is correct |
15 |
Correct |
0 ms |
14524 KB |
Output is correct |
16 |
Correct |
0 ms |
14524 KB |
Output is correct |
17 |
Correct |
0 ms |
14524 KB |
Output is correct |
18 |
Correct |
0 ms |
14524 KB |
Output is correct |
19 |
Correct |
0 ms |
14524 KB |
Output is correct |
20 |
Correct |
0 ms |
14524 KB |
Output is correct |
21 |
Correct |
0 ms |
14524 KB |
Output is correct |
22 |
Correct |
0 ms |
14524 KB |
Output is correct |
23 |
Correct |
0 ms |
14524 KB |
Output is correct |
24 |
Correct |
0 ms |
14524 KB |
Output is correct |
25 |
Correct |
0 ms |
14524 KB |
Output is correct |
26 |
Correct |
0 ms |
14524 KB |
Output is correct |
27 |
Correct |
0 ms |
14524 KB |
Output is correct |
28 |
Correct |
0 ms |
14524 KB |
Output is correct |
29 |
Correct |
0 ms |
14524 KB |
Output is correct |
30 |
Correct |
0 ms |
14524 KB |
Output is correct |
31 |
Correct |
0 ms |
14524 KB |
Output is correct |
32 |
Correct |
0 ms |
14524 KB |
Output is correct |
33 |
Correct |
0 ms |
14524 KB |
Output is correct |
34 |
Correct |
0 ms |
14524 KB |
Output is correct |
35 |
Correct |
0 ms |
14524 KB |
Output is correct |
36 |
Correct |
0 ms |
14524 KB |
Output is correct |
37 |
Correct |
0 ms |
14524 KB |
Output is correct |
38 |
Correct |
0 ms |
14524 KB |
Output is correct |
39 |
Correct |
0 ms |
14524 KB |
Output is correct |
40 |
Correct |
0 ms |
14524 KB |
Output is correct |
41 |
Correct |
0 ms |
14524 KB |
Output is correct |
42 |
Correct |
0 ms |
14524 KB |
Output is correct |
43 |
Correct |
0 ms |
14524 KB |
Output is correct |
44 |
Correct |
0 ms |
14524 KB |
Output is correct |
45 |
Correct |
0 ms |
14524 KB |
Output is correct |
46 |
Correct |
0 ms |
14524 KB |
Output is correct |
47 |
Correct |
0 ms |
14524 KB |
Output is correct |
48 |
Correct |
0 ms |
14524 KB |
Output is correct |
49 |
Correct |
0 ms |
14524 KB |
Output is correct |
50 |
Correct |
0 ms |
14524 KB |
Output is correct |
51 |
Correct |
0 ms |
14524 KB |
Output is correct |
52 |
Correct |
229 ms |
14524 KB |
Output is correct |
53 |
Correct |
209 ms |
14524 KB |
Output is correct |
54 |
Correct |
149 ms |
14524 KB |
Output is correct |
55 |
Correct |
189 ms |
14524 KB |
Output is correct |
56 |
Correct |
169 ms |
14524 KB |
Output is correct |
57 |
Correct |
183 ms |
14524 KB |
Output is correct |
58 |
Correct |
176 ms |
14524 KB |
Output is correct |
59 |
Correct |
186 ms |
14524 KB |
Output is correct |
60 |
Correct |
153 ms |
14524 KB |
Output is correct |
61 |
Correct |
173 ms |
14524 KB |
Output is correct |
62 |
Correct |
166 ms |
14524 KB |
Output is correct |
63 |
Correct |
123 ms |
14524 KB |
Output is correct |
64 |
Correct |
176 ms |
14524 KB |
Output is correct |
65 |
Correct |
199 ms |
14524 KB |
Output is correct |
66 |
Correct |
213 ms |
14524 KB |
Output is correct |
67 |
Correct |
189 ms |
14524 KB |
Output is correct |
68 |
Correct |
213 ms |
14524 KB |
Output is correct |
69 |
Correct |
226 ms |
14524 KB |
Output is correct |
70 |
Correct |
209 ms |
14524 KB |
Output is correct |
71 |
Correct |
186 ms |
14524 KB |
Output is correct |
72 |
Correct |
209 ms |
14524 KB |
Output is correct |
73 |
Correct |
213 ms |
14524 KB |
Output is correct |
74 |
Correct |
216 ms |
14524 KB |
Output is correct |
75 |
Correct |
223 ms |
14524 KB |
Output is correct |
76 |
Correct |
213 ms |
14524 KB |
Output is correct |
77 |
Correct |
159 ms |
14524 KB |
Output is correct |
78 |
Correct |
166 ms |
14524 KB |
Output is correct |
79 |
Correct |
223 ms |
14524 KB |
Output is correct |
80 |
Correct |
226 ms |
14524 KB |
Output is correct |