#include <bits/stdc++.h>
using namespace std;
typedef pair<int64_t, int64_t> pii;
int64_t get (const pii& p, const int64_t& v)
{ return p.first * v + p.second; }
const int kN = 200'002;
int N, M;
int64_t X, W, T;
pii refill[kN], passenger[kN];
int64_t preC[kN];
int prev_passenger[kN];
int64_t dp[kN];
pii nd[kN * 4];
void insert(pii p, int i = 1, int l = 0, int r = M) {
if (l >= r) return;
int m = (l + r) / 2;
if (get(p, m) < get(nd[i], m))
swap(p, nd[i]);
if (l + 1 == r) return;
if (nd[i].first < p.first) insert(p, i * 2, l, m);
if (nd[i].first > p.first) insert(p, i * 2 + 1, m + 1, r);
}
int64_t query(int p, int i = 1, int l = 0, int r = M) {
if (l >= r) return LLONG_MAX;
int m = (l + r) / 2;
if (l + 1 == r or p == m) return get(nd[i], p);
return min(get(nd[i], p), p < m ? query(p, i * 2, l, m) : query(p, i * 2 + 1, m + 1, r));
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> X >> N >> M >> W >> T;
for (int i = 0; i < N; ++i) {
int64_t S; cin >> S;
refill[i].first = S % T;
refill[i].second = S / T;
}
for (int i = 0; i < M; ++i) {
cin >> passenger[i].first;
cin >> passenger[i].second;
}
refill[N] = pii(X % T, X / T);
sort(refill, refill + N + 1);
sort(passenger, passenger + M);
for (int i = 0; i <= N; ++i)
prev_passenger[i] = lower_bound(passenger, passenger + M, refill[i]) - passenger - 1;
for (int i = 0; i < M; ++i)
preC[i + 1] = preC[i] + passenger[i].second;
fill(nd, nd + M * 4, pii(0, LLONG_MAX));
for (int i = M - 1, j = N; i >= 0; --i) {
for (; j >= 0; --j) {
int r = prev_passenger[j];
if (r < i) break;
insert(pii(-W * refill[j].second, preC[r + 1] + dp[r + 1] + W * (r + 1) * refill[j].second));
}
dp[i] = dp[i + 1] + W * (X / T + (passenger[i].first % T < X % T));
dp[i] = min(dp[i], query(i) - preC[i]);
}
cout << dp[0] + W * (X / T + 1) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 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 |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
0 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 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 |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
0 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
460 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
460 KB |
Output is correct |
41 |
Correct |
2 ms |
460 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Correct |
1 ms |
460 KB |
Output is correct |
44 |
Correct |
1 ms |
460 KB |
Output is correct |
45 |
Correct |
2 ms |
512 KB |
Output is correct |
46 |
Correct |
1 ms |
460 KB |
Output is correct |
47 |
Correct |
2 ms |
460 KB |
Output is correct |
48 |
Correct |
1 ms |
460 KB |
Output is correct |
49 |
Correct |
1 ms |
460 KB |
Output is correct |
50 |
Correct |
2 ms |
512 KB |
Output is correct |
51 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 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 |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
0 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
460 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
460 KB |
Output is correct |
41 |
Correct |
2 ms |
460 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Correct |
1 ms |
460 KB |
Output is correct |
44 |
Correct |
1 ms |
460 KB |
Output is correct |
45 |
Correct |
2 ms |
512 KB |
Output is correct |
46 |
Correct |
1 ms |
460 KB |
Output is correct |
47 |
Correct |
2 ms |
460 KB |
Output is correct |
48 |
Correct |
1 ms |
460 KB |
Output is correct |
49 |
Correct |
1 ms |
460 KB |
Output is correct |
50 |
Correct |
2 ms |
512 KB |
Output is correct |
51 |
Correct |
2 ms |
460 KB |
Output is correct |
52 |
Correct |
156 ms |
22916 KB |
Output is correct |
53 |
Correct |
124 ms |
22948 KB |
Output is correct |
54 |
Correct |
137 ms |
23148 KB |
Output is correct |
55 |
Correct |
172 ms |
22996 KB |
Output is correct |
56 |
Correct |
135 ms |
22932 KB |
Output is correct |
57 |
Correct |
140 ms |
23940 KB |
Output is correct |
58 |
Correct |
136 ms |
22952 KB |
Output is correct |
59 |
Correct |
149 ms |
23000 KB |
Output is correct |
60 |
Correct |
130 ms |
22992 KB |
Output is correct |
61 |
Correct |
130 ms |
22896 KB |
Output is correct |
62 |
Correct |
153 ms |
22968 KB |
Output is correct |
63 |
Correct |
136 ms |
22988 KB |
Output is correct |
64 |
Correct |
92 ms |
22980 KB |
Output is correct |
65 |
Correct |
133 ms |
22948 KB |
Output is correct |
66 |
Correct |
136 ms |
22912 KB |
Output is correct |
67 |
Correct |
130 ms |
22896 KB |
Output is correct |
68 |
Correct |
128 ms |
22944 KB |
Output is correct |
69 |
Correct |
143 ms |
22952 KB |
Output is correct |
70 |
Correct |
148 ms |
23028 KB |
Output is correct |
71 |
Correct |
146 ms |
23092 KB |
Output is correct |
72 |
Correct |
147 ms |
22948 KB |
Output is correct |
73 |
Correct |
143 ms |
22980 KB |
Output is correct |
74 |
Correct |
150 ms |
22948 KB |
Output is correct |
75 |
Correct |
152 ms |
22980 KB |
Output is correct |
76 |
Correct |
145 ms |
22980 KB |
Output is correct |
77 |
Correct |
120 ms |
22984 KB |
Output is correct |
78 |
Correct |
122 ms |
22876 KB |
Output is correct |
79 |
Correct |
141 ms |
22908 KB |
Output is correct |
80 |
Correct |
141 ms |
23024 KB |
Output is correct |