#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#define ll long long
#define ld long double
using namespace std;
array <ll, 2> A[200000];
vector <ll> V;
ll mn[200000], ps[200000];
ll x, n, m, w, t, p, a, b, l, r, mid, S[200001], dp[200000];
ld ep = 1e-8, z;
struct Line{
ll m;
ll c;
};
ld intx(Line I, Line J) {
return (ld)(I.c-J.c)/(J.m-I.m);
}
vector <Line> L;
int main() {
cin >> x >> n >> m >> w >> t;
for (int i=0; i<n; ++i) {
cin >> S[i];
}
S[n] = x;
sort(S, S+n+1);
for (int i=0; i<m; ++i) {
cin >> A[i][0] >> A[i][1];
}
sort(A, A+m);
for (int i=0; i<m; ++i) {
V.push_back(A[i][0]);
mn[i] = 1e18;
ps[i] = (i ? ps[i-1] : 0) + A[i][1];
}
for (int i=0; i<=n; ++i) {
auto it = lower_bound(V.begin(), V.end(), S[i] % t);
if (it != V.begin()) {
it = prev(it);
mn[it-V.begin()] = min(mn[it-V.begin()], S[i] / t);
}
}
L.push_back({w, 0});
for (ll i=0; i<m; ++i) {
dp[i] = (i ? dp[i-1] : 0) + (ll)((x-A[i][0]) / t + 1) * w;
if (mn[i] != 1e18) {
l = 0, r = L.size()-1;
while (l < r) {
mid = (l+r+1)/2;
if (!mid) x = 0;
else z = intx(L[mid-1], L[mid]);
if ((ld)mn[i]-z >= -ep) l = mid;
else r = mid-1;
}
dp[i] = min(dp[i], L[l].m * mn[i] + L[l].c + mn[i] * w * i + ps[i]);
}
Line nw = {-i * w, dp[i] - ps[i]};
while (L.size() >= 2) {
auto I = L.back();
auto J = L[L.size()-2];
if (intx(J, I)-intx(J, nw) >= -ep) L.pop_back();
else break;
}
L.push_back(nw);
}
cout << dp[m-1] + (x/t+1) * w << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6600 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6600 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6592 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6592 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6504 KB |
Output is correct |
20 |
Correct |
1 ms |
6744 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6600 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6600 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6592 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6592 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6504 KB |
Output is correct |
20 |
Correct |
1 ms |
6744 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6488 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6748 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6592 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6488 KB |
Output is correct |
37 |
Correct |
1 ms |
6488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6600 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6600 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6592 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6592 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6504 KB |
Output is correct |
20 |
Correct |
1 ms |
6744 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6488 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6748 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6592 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6488 KB |
Output is correct |
37 |
Correct |
1 ms |
6488 KB |
Output is correct |
38 |
Correct |
3 ms |
6488 KB |
Output is correct |
39 |
Correct |
3 ms |
6492 KB |
Output is correct |
40 |
Correct |
3 ms |
6496 KB |
Output is correct |
41 |
Correct |
2 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6492 KB |
Output is correct |
43 |
Correct |
2 ms |
6492 KB |
Output is correct |
44 |
Correct |
2 ms |
6492 KB |
Output is correct |
45 |
Correct |
2 ms |
6492 KB |
Output is correct |
46 |
Correct |
2 ms |
6492 KB |
Output is correct |
47 |
Correct |
2 ms |
6492 KB |
Output is correct |
48 |
Correct |
4 ms |
6492 KB |
Output is correct |
49 |
Correct |
2 ms |
6492 KB |
Output is correct |
50 |
Correct |
2 ms |
6488 KB |
Output is correct |
51 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6600 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6600 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6592 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6592 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6504 KB |
Output is correct |
20 |
Correct |
1 ms |
6744 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6488 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6748 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6592 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6488 KB |
Output is correct |
37 |
Correct |
1 ms |
6488 KB |
Output is correct |
38 |
Correct |
3 ms |
6488 KB |
Output is correct |
39 |
Correct |
3 ms |
6492 KB |
Output is correct |
40 |
Correct |
3 ms |
6496 KB |
Output is correct |
41 |
Correct |
2 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6492 KB |
Output is correct |
43 |
Correct |
2 ms |
6492 KB |
Output is correct |
44 |
Correct |
2 ms |
6492 KB |
Output is correct |
45 |
Correct |
2 ms |
6492 KB |
Output is correct |
46 |
Correct |
2 ms |
6492 KB |
Output is correct |
47 |
Correct |
2 ms |
6492 KB |
Output is correct |
48 |
Correct |
4 ms |
6492 KB |
Output is correct |
49 |
Correct |
2 ms |
6492 KB |
Output is correct |
50 |
Correct |
2 ms |
6488 KB |
Output is correct |
51 |
Correct |
2 ms |
6492 KB |
Output is correct |
52 |
Correct |
205 ms |
17432 KB |
Output is correct |
53 |
Correct |
190 ms |
17604 KB |
Output is correct |
54 |
Correct |
183 ms |
16660 KB |
Output is correct |
55 |
Correct |
165 ms |
16840 KB |
Output is correct |
56 |
Correct |
170 ms |
17096 KB |
Output is correct |
57 |
Correct |
173 ms |
16836 KB |
Output is correct |
58 |
Correct |
177 ms |
17352 KB |
Output is correct |
59 |
Correct |
165 ms |
16784 KB |
Output is correct |
60 |
Correct |
166 ms |
16580 KB |
Output is correct |
61 |
Correct |
165 ms |
16668 KB |
Output is correct |
62 |
Correct |
163 ms |
16840 KB |
Output is correct |
63 |
Correct |
131 ms |
20628 KB |
Output is correct |
64 |
Correct |
173 ms |
17556 KB |
Output is correct |
65 |
Correct |
190 ms |
17352 KB |
Output is correct |
66 |
Correct |
187 ms |
17352 KB |
Output is correct |
67 |
Correct |
202 ms |
17352 KB |
Output is correct |
68 |
Correct |
201 ms |
17568 KB |
Output is correct |
69 |
Correct |
198 ms |
17312 KB |
Output is correct |
70 |
Correct |
203 ms |
17316 KB |
Output is correct |
71 |
Correct |
197 ms |
17096 KB |
Output is correct |
72 |
Correct |
194 ms |
17316 KB |
Output is correct |
73 |
Correct |
204 ms |
17348 KB |
Output is correct |
74 |
Correct |
223 ms |
17172 KB |
Output is correct |
75 |
Correct |
197 ms |
17352 KB |
Output is correct |
76 |
Correct |
205 ms |
17348 KB |
Output is correct |
77 |
Correct |
172 ms |
17096 KB |
Output is correct |
78 |
Correct |
187 ms |
17352 KB |
Output is correct |
79 |
Correct |
188 ms |
16836 KB |
Output is correct |
80 |
Correct |
181 ms |
16836 KB |
Output is correct |