#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN=2e5;
int n, m;
ll x, w, t, s[mxN+1], a1, pc[mxN+1], dp[mxN+1];
array<ll, 2> s1[mxN+1], d[mxN], st[1<<19];
void upd(array<ll, 2> a, int i=1, int l2=0, int r2=m-1) {
int m2=(l2+r2)/2;
if(st[i][0]*m2+st[i][1]>a[0]*m2+a[1])
swap(st[i], a);
if(l2==r2)
return;
if(a[0]*l2+a[1]<st[i][0]*l2+st[i][1])
upd(a, 2*i, l2, m2);
else
upd(a, 2*i+1, m2+1, r2);
}
ll qry(int x, int i=1, int l2=0, int r2=m-1) {
int m2=(l2+r2)/2;
return min(st[i][0]*x+st[i][1], l2<r2?(x<=m2?qry(x, 2*i, l2, m2):qry(x, 2*i+1, m2+1, r2)):pc[m]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> x >> n >> m >> w >> t;
for(int i=0; i<n; ++i) {
cin >> s[i];
s1[i]={s[i]%t, i};
}
s[n]=x;
s1[n]={x%t, n};
sort(s1, s1+n+1);
a1=x/t+1;
for(int i=0; i<m; ++i) {
cin >> d[i][0] >> d[i][1];
a1+=(x-d[i][0]+t)/t;
}
sort(d, d+m);
for(int i=0; i<m; ++i)
pc[i+1]=pc[i]+d[i][1];
fill(st, st+(1<<19), array<ll, 2>{0ll, pc[m]});
for(int i1=m-1, i2=n; i1>=0; --i1) {
while(i2>=0&&s1[i2][0]>d[i1][0]) {
int l2=lower_bound(d, d+i1+1, array<ll, 2>{x%t+1, 0ll})-d;
ll b=s[s1[i2--][1]]/t-x/t;
upd({-w*b, pc[i1+1]+(i1+1)*w*b+dp[i1+1]});
upd({-w*(b-1), pc[i1+1]+(i1-l2+1)*w*b+l2*w*(b-1)+dp[i1+1]});
}
dp[i1]=min(qry(i1)-pc[i1], dp[i1+1]);
}
cout << a1*w+dp[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8568 KB |
Output is correct |
2 |
Correct |
8 ms |
8572 KB |
Output is correct |
3 |
Correct |
8 ms |
8568 KB |
Output is correct |
4 |
Correct |
8 ms |
8568 KB |
Output is correct |
5 |
Correct |
8 ms |
8568 KB |
Output is correct |
6 |
Correct |
8 ms |
8612 KB |
Output is correct |
7 |
Correct |
8 ms |
8568 KB |
Output is correct |
8 |
Correct |
8 ms |
8572 KB |
Output is correct |
9 |
Correct |
8 ms |
8568 KB |
Output is correct |
10 |
Correct |
8 ms |
8572 KB |
Output is correct |
11 |
Correct |
8 ms |
8568 KB |
Output is correct |
12 |
Correct |
8 ms |
8568 KB |
Output is correct |
13 |
Correct |
8 ms |
8568 KB |
Output is correct |
14 |
Correct |
8 ms |
8568 KB |
Output is correct |
15 |
Correct |
8 ms |
8568 KB |
Output is correct |
16 |
Correct |
8 ms |
8568 KB |
Output is correct |
17 |
Correct |
8 ms |
8576 KB |
Output is correct |
18 |
Correct |
8 ms |
8616 KB |
Output is correct |
19 |
Correct |
8 ms |
8568 KB |
Output is correct |
20 |
Correct |
8 ms |
8568 KB |
Output is correct |
21 |
Correct |
8 ms |
8568 KB |
Output is correct |
22 |
Correct |
8 ms |
8568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8568 KB |
Output is correct |
2 |
Correct |
8 ms |
8572 KB |
Output is correct |
3 |
Correct |
8 ms |
8568 KB |
Output is correct |
4 |
Correct |
8 ms |
8568 KB |
Output is correct |
5 |
Correct |
8 ms |
8568 KB |
Output is correct |
6 |
Correct |
8 ms |
8612 KB |
Output is correct |
7 |
Correct |
8 ms |
8568 KB |
Output is correct |
8 |
Correct |
8 ms |
8572 KB |
Output is correct |
9 |
Correct |
8 ms |
8568 KB |
Output is correct |
10 |
Correct |
8 ms |
8572 KB |
Output is correct |
11 |
Correct |
8 ms |
8568 KB |
Output is correct |
12 |
Correct |
8 ms |
8568 KB |
Output is correct |
13 |
Correct |
8 ms |
8568 KB |
Output is correct |
14 |
Correct |
8 ms |
8568 KB |
Output is correct |
15 |
Correct |
8 ms |
8568 KB |
Output is correct |
16 |
Correct |
8 ms |
8568 KB |
Output is correct |
17 |
Correct |
8 ms |
8576 KB |
Output is correct |
18 |
Correct |
8 ms |
8616 KB |
Output is correct |
19 |
Correct |
8 ms |
8568 KB |
Output is correct |
20 |
Correct |
8 ms |
8568 KB |
Output is correct |
21 |
Correct |
8 ms |
8568 KB |
Output is correct |
22 |
Correct |
8 ms |
8568 KB |
Output is correct |
23 |
Correct |
8 ms |
8568 KB |
Output is correct |
24 |
Correct |
8 ms |
8572 KB |
Output is correct |
25 |
Correct |
8 ms |
8568 KB |
Output is correct |
26 |
Correct |
8 ms |
8568 KB |
Output is correct |
27 |
Correct |
8 ms |
8568 KB |
Output is correct |
28 |
Correct |
8 ms |
8568 KB |
Output is correct |
29 |
Correct |
8 ms |
8568 KB |
Output is correct |
30 |
Correct |
8 ms |
8568 KB |
Output is correct |
31 |
Correct |
7 ms |
8612 KB |
Output is correct |
32 |
Correct |
7 ms |
8540 KB |
Output is correct |
33 |
Correct |
7 ms |
8568 KB |
Output is correct |
34 |
Correct |
7 ms |
8568 KB |
Output is correct |
35 |
Correct |
8 ms |
8568 KB |
Output is correct |
36 |
Correct |
7 ms |
8568 KB |
Output is correct |
37 |
Correct |
8 ms |
8568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8568 KB |
Output is correct |
2 |
Correct |
8 ms |
8572 KB |
Output is correct |
3 |
Correct |
8 ms |
8568 KB |
Output is correct |
4 |
Correct |
8 ms |
8568 KB |
Output is correct |
5 |
Correct |
8 ms |
8568 KB |
Output is correct |
6 |
Correct |
8 ms |
8612 KB |
Output is correct |
7 |
Correct |
8 ms |
8568 KB |
Output is correct |
8 |
Correct |
8 ms |
8572 KB |
Output is correct |
9 |
Correct |
8 ms |
8568 KB |
Output is correct |
10 |
Correct |
8 ms |
8572 KB |
Output is correct |
11 |
Correct |
8 ms |
8568 KB |
Output is correct |
12 |
Correct |
8 ms |
8568 KB |
Output is correct |
13 |
Correct |
8 ms |
8568 KB |
Output is correct |
14 |
Correct |
8 ms |
8568 KB |
Output is correct |
15 |
Correct |
8 ms |
8568 KB |
Output is correct |
16 |
Correct |
8 ms |
8568 KB |
Output is correct |
17 |
Correct |
8 ms |
8576 KB |
Output is correct |
18 |
Correct |
8 ms |
8616 KB |
Output is correct |
19 |
Correct |
8 ms |
8568 KB |
Output is correct |
20 |
Correct |
8 ms |
8568 KB |
Output is correct |
21 |
Correct |
8 ms |
8568 KB |
Output is correct |
22 |
Correct |
8 ms |
8568 KB |
Output is correct |
23 |
Correct |
8 ms |
8568 KB |
Output is correct |
24 |
Correct |
8 ms |
8572 KB |
Output is correct |
25 |
Correct |
8 ms |
8568 KB |
Output is correct |
26 |
Correct |
8 ms |
8568 KB |
Output is correct |
27 |
Correct |
8 ms |
8568 KB |
Output is correct |
28 |
Correct |
8 ms |
8568 KB |
Output is correct |
29 |
Correct |
8 ms |
8568 KB |
Output is correct |
30 |
Correct |
8 ms |
8568 KB |
Output is correct |
31 |
Correct |
7 ms |
8612 KB |
Output is correct |
32 |
Correct |
7 ms |
8540 KB |
Output is correct |
33 |
Correct |
7 ms |
8568 KB |
Output is correct |
34 |
Correct |
7 ms |
8568 KB |
Output is correct |
35 |
Correct |
8 ms |
8568 KB |
Output is correct |
36 |
Correct |
7 ms |
8568 KB |
Output is correct |
37 |
Correct |
8 ms |
8568 KB |
Output is correct |
38 |
Correct |
10 ms |
8696 KB |
Output is correct |
39 |
Correct |
10 ms |
8696 KB |
Output is correct |
40 |
Correct |
10 ms |
8868 KB |
Output is correct |
41 |
Correct |
9 ms |
8700 KB |
Output is correct |
42 |
Correct |
10 ms |
8696 KB |
Output is correct |
43 |
Correct |
9 ms |
8696 KB |
Output is correct |
44 |
Correct |
9 ms |
8696 KB |
Output is correct |
45 |
Correct |
9 ms |
8696 KB |
Output is correct |
46 |
Correct |
10 ms |
8696 KB |
Output is correct |
47 |
Correct |
10 ms |
8696 KB |
Output is correct |
48 |
Correct |
10 ms |
8728 KB |
Output is correct |
49 |
Correct |
9 ms |
8696 KB |
Output is correct |
50 |
Correct |
10 ms |
8756 KB |
Output is correct |
51 |
Correct |
10 ms |
8696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8568 KB |
Output is correct |
2 |
Correct |
8 ms |
8572 KB |
Output is correct |
3 |
Correct |
8 ms |
8568 KB |
Output is correct |
4 |
Correct |
8 ms |
8568 KB |
Output is correct |
5 |
Correct |
8 ms |
8568 KB |
Output is correct |
6 |
Correct |
8 ms |
8612 KB |
Output is correct |
7 |
Correct |
8 ms |
8568 KB |
Output is correct |
8 |
Correct |
8 ms |
8572 KB |
Output is correct |
9 |
Correct |
8 ms |
8568 KB |
Output is correct |
10 |
Correct |
8 ms |
8572 KB |
Output is correct |
11 |
Correct |
8 ms |
8568 KB |
Output is correct |
12 |
Correct |
8 ms |
8568 KB |
Output is correct |
13 |
Correct |
8 ms |
8568 KB |
Output is correct |
14 |
Correct |
8 ms |
8568 KB |
Output is correct |
15 |
Correct |
8 ms |
8568 KB |
Output is correct |
16 |
Correct |
8 ms |
8568 KB |
Output is correct |
17 |
Correct |
8 ms |
8576 KB |
Output is correct |
18 |
Correct |
8 ms |
8616 KB |
Output is correct |
19 |
Correct |
8 ms |
8568 KB |
Output is correct |
20 |
Correct |
8 ms |
8568 KB |
Output is correct |
21 |
Correct |
8 ms |
8568 KB |
Output is correct |
22 |
Correct |
8 ms |
8568 KB |
Output is correct |
23 |
Correct |
8 ms |
8568 KB |
Output is correct |
24 |
Correct |
8 ms |
8572 KB |
Output is correct |
25 |
Correct |
8 ms |
8568 KB |
Output is correct |
26 |
Correct |
8 ms |
8568 KB |
Output is correct |
27 |
Correct |
8 ms |
8568 KB |
Output is correct |
28 |
Correct |
8 ms |
8568 KB |
Output is correct |
29 |
Correct |
8 ms |
8568 KB |
Output is correct |
30 |
Correct |
8 ms |
8568 KB |
Output is correct |
31 |
Correct |
7 ms |
8612 KB |
Output is correct |
32 |
Correct |
7 ms |
8540 KB |
Output is correct |
33 |
Correct |
7 ms |
8568 KB |
Output is correct |
34 |
Correct |
7 ms |
8568 KB |
Output is correct |
35 |
Correct |
8 ms |
8568 KB |
Output is correct |
36 |
Correct |
7 ms |
8568 KB |
Output is correct |
37 |
Correct |
8 ms |
8568 KB |
Output is correct |
38 |
Correct |
10 ms |
8696 KB |
Output is correct |
39 |
Correct |
10 ms |
8696 KB |
Output is correct |
40 |
Correct |
10 ms |
8868 KB |
Output is correct |
41 |
Correct |
9 ms |
8700 KB |
Output is correct |
42 |
Correct |
10 ms |
8696 KB |
Output is correct |
43 |
Correct |
9 ms |
8696 KB |
Output is correct |
44 |
Correct |
9 ms |
8696 KB |
Output is correct |
45 |
Correct |
9 ms |
8696 KB |
Output is correct |
46 |
Correct |
10 ms |
8696 KB |
Output is correct |
47 |
Correct |
10 ms |
8696 KB |
Output is correct |
48 |
Correct |
10 ms |
8728 KB |
Output is correct |
49 |
Correct |
9 ms |
8696 KB |
Output is correct |
50 |
Correct |
10 ms |
8756 KB |
Output is correct |
51 |
Correct |
10 ms |
8696 KB |
Output is correct |
52 |
Correct |
253 ms |
25188 KB |
Output is correct |
53 |
Correct |
196 ms |
25336 KB |
Output is correct |
54 |
Correct |
262 ms |
24440 KB |
Output is correct |
55 |
Correct |
257 ms |
24620 KB |
Output is correct |
56 |
Correct |
257 ms |
24984 KB |
Output is correct |
57 |
Correct |
246 ms |
24840 KB |
Output is correct |
58 |
Correct |
256 ms |
25304 KB |
Output is correct |
59 |
Correct |
258 ms |
24748 KB |
Output is correct |
60 |
Correct |
247 ms |
24568 KB |
Output is correct |
61 |
Correct |
254 ms |
24592 KB |
Output is correct |
62 |
Correct |
249 ms |
24680 KB |
Output is correct |
63 |
Correct |
175 ms |
23544 KB |
Output is correct |
64 |
Correct |
122 ms |
25420 KB |
Output is correct |
65 |
Correct |
208 ms |
25396 KB |
Output is correct |
66 |
Correct |
210 ms |
25208 KB |
Output is correct |
67 |
Correct |
214 ms |
25312 KB |
Output is correct |
68 |
Correct |
208 ms |
25360 KB |
Output is correct |
69 |
Correct |
249 ms |
24976 KB |
Output is correct |
70 |
Correct |
238 ms |
25060 KB |
Output is correct |
71 |
Correct |
240 ms |
25080 KB |
Output is correct |
72 |
Correct |
228 ms |
25080 KB |
Output is correct |
73 |
Correct |
249 ms |
25060 KB |
Output is correct |
74 |
Correct |
242 ms |
25132 KB |
Output is correct |
75 |
Correct |
241 ms |
25208 KB |
Output is correct |
76 |
Correct |
240 ms |
25352 KB |
Output is correct |
77 |
Correct |
232 ms |
24916 KB |
Output is correct |
78 |
Correct |
276 ms |
25208 KB |
Output is correct |
79 |
Correct |
240 ms |
24696 KB |
Output is correct |
80 |
Correct |
241 ms |
24568 KB |
Output is correct |