#include <bits/stdc++.h>
using namespace std;
long long x;
int n,m;
long long w,t;
vector<long long> s;
long long c1[200000];
typedef pair<long long,long long> P;
vector<P> vec;
long long mn[200001];
long long psum[200001];
long long dp[200001];
long long MX;
const long long INF=3e18;
struct Node {
P line;
int l,r;
};
vector<Node> seg;
Node emp={P(0,INF),-1,-1};
long long f(P line,long long xq) {
return line.first*xq+line.second;
}
void insert(P line,int node=0,long long xl=0,long long xr=MX) {
long long mid=(xl+xr)/2;
P low=line;
P high=seg[node].line;
if (f(low,xl)>f(high,xl)) {
swap(low,high);
}
if (f(low,xr)<=f(high,xr)) {
seg[node].line=low;
return;
}
if (f(low,mid)<=f(high,mid)) {
seg[node].line=low;
if (seg[node].r==-1) {
seg[node].r=seg.size();
seg.push_back(emp);
}
insert(high,seg[node].r,mid+1,xr);
}
else {
seg[node].line=high;
if (seg[node].l==-1) {
seg[node].l=seg.size();
seg.push_back(emp);
}
insert(low,seg[node].l,xl,mid);
}
}
long long query(long long xq,int node=0,long long xl=0,long long xr=MX) {
if (node==-1) {
return INF;
}
long long ret=f(seg[node].line,xq);
if (xl==xr) {
return ret;
}
long long mid=(xl+xr)/2;
if (xq<=mid) {
ret=min(ret,query(xq,seg[node].l,xl,mid));
}
else {
ret=min(ret,query(xq,seg[node].r,mid+1,xr));
}
return ret;
}
int main() {
scanf("%lld %d %d %lld %lld",&x,&n,&m,&w,&t);
for(int i=0;i<n;i++) {
long long val;
scanf("%lld",&val);
s.push_back(val);
}
seg.push_back(emp);
s.push_back(x);
sort(s.begin(),s.end());
for(int i=0;i<m;i++) {
long long d;
long long c;
scanf("%lld %lld",&d,&c);
vec.push_back(P(d,c));
}
vec.push_back(P(0,0));
sort(vec.begin(),vec.end());
for(int i=0;i<=m;i++) {
mn[i]=-1;
}
for(int i=0;i<s.size();i++) {
int ind=lower_bound(vec.begin(),vec.end(),P(s[i]%t,-1))-vec.begin()-1;
if (mn[ind]==-1) {
mn[ind]=s[i]/t;
}
}
MX=x/t;
dp[0]=((x/t)+1)*w;
insert(P(0,dp[0]));
for(int i=1;i<=m;i++) {
psum[i]=psum[i-1]+vec[i].second;
long long cnt=x/t+(vec[i].first<x%t);
dp[i]=9e18;
dp[i]=min(dp[i],dp[i-1]+cnt*w);
if (mn[i]!=-1) {
dp[i]=min(dp[i],query(mn[i])+psum[i]+w*mn[i]*i);
}
insert(P(-w*i,dp[i]-psum[i]));
//printf(".%lld\n",dp[i]);
}
printf("%lld",dp[m]);
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:97:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for(int i=0;i<s.size();i++) {
| ~^~~~~~~~~
coach.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | scanf("%lld %d %d %lld %lld",&x,&n,&m,&w,&t);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | scanf("%lld",&val);
| ~~~~~^~~~~~~~~~~~~
coach.cpp:89:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | scanf("%lld %lld",&d,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
260 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
240 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
260 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
240 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
1 ms |
316 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
308 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
320 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
260 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
240 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
1 ms |
316 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
308 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
320 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
2 ms |
468 KB |
Output is correct |
39 |
Correct |
4 ms |
468 KB |
Output is correct |
40 |
Correct |
3 ms |
392 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
2 ms |
436 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
2 ms |
456 KB |
Output is correct |
45 |
Correct |
2 ms |
468 KB |
Output is correct |
46 |
Correct |
2 ms |
468 KB |
Output is correct |
47 |
Correct |
3 ms |
452 KB |
Output is correct |
48 |
Correct |
2 ms |
392 KB |
Output is correct |
49 |
Correct |
2 ms |
460 KB |
Output is correct |
50 |
Correct |
2 ms |
468 KB |
Output is correct |
51 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
260 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
240 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
1 ms |
316 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
308 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
320 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
2 ms |
468 KB |
Output is correct |
39 |
Correct |
4 ms |
468 KB |
Output is correct |
40 |
Correct |
3 ms |
392 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
2 ms |
436 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
2 ms |
456 KB |
Output is correct |
45 |
Correct |
2 ms |
468 KB |
Output is correct |
46 |
Correct |
2 ms |
468 KB |
Output is correct |
47 |
Correct |
3 ms |
452 KB |
Output is correct |
48 |
Correct |
2 ms |
392 KB |
Output is correct |
49 |
Correct |
2 ms |
460 KB |
Output is correct |
50 |
Correct |
2 ms |
468 KB |
Output is correct |
51 |
Correct |
2 ms |
468 KB |
Output is correct |
52 |
Correct |
171 ms |
12804 KB |
Output is correct |
53 |
Correct |
208 ms |
10348 KB |
Output is correct |
54 |
Correct |
163 ms |
10404 KB |
Output is correct |
55 |
Correct |
148 ms |
10300 KB |
Output is correct |
56 |
Correct |
161 ms |
10232 KB |
Output is correct |
57 |
Correct |
134 ms |
10240 KB |
Output is correct |
58 |
Correct |
138 ms |
10224 KB |
Output is correct |
59 |
Correct |
127 ms |
10280 KB |
Output is correct |
60 |
Correct |
129 ms |
10260 KB |
Output is correct |
61 |
Correct |
127 ms |
10308 KB |
Output is correct |
62 |
Correct |
167 ms |
10328 KB |
Output is correct |
63 |
Correct |
130 ms |
18928 KB |
Output is correct |
64 |
Correct |
147 ms |
15636 KB |
Output is correct |
65 |
Correct |
190 ms |
15516 KB |
Output is correct |
66 |
Correct |
169 ms |
15500 KB |
Output is correct |
67 |
Correct |
163 ms |
15552 KB |
Output is correct |
68 |
Correct |
176 ms |
15508 KB |
Output is correct |
69 |
Correct |
214 ms |
15264 KB |
Output is correct |
70 |
Correct |
166 ms |
15200 KB |
Output is correct |
71 |
Correct |
163 ms |
15300 KB |
Output is correct |
72 |
Correct |
169 ms |
15256 KB |
Output is correct |
73 |
Correct |
158 ms |
15300 KB |
Output is correct |
74 |
Correct |
149 ms |
15356 KB |
Output is correct |
75 |
Correct |
211 ms |
15436 KB |
Output is correct |
76 |
Correct |
175 ms |
15500 KB |
Output is correct |
77 |
Correct |
136 ms |
15172 KB |
Output is correct |
78 |
Correct |
154 ms |
15460 KB |
Output is correct |
79 |
Correct |
228 ms |
14864 KB |
Output is correct |
80 |
Correct |
155 ms |
14944 KB |
Output is correct |