#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair <LL, LL> PLL;
constexpr LL INF = 1LL * 1e18;
constexpr int NMAX = 2e5 + 5;
LL Value (LL x, PLL line) {
return line.first * x + line.second;
}
class LiChao {
private:
vector <PLL> arb;
int sz;
void Update (int nod, int a, int b, PLL line) {
if (a >= b) return;
int mij = (a + b) / 2;
bool st = Value(a, arb[nod]) < Value(a, line);
bool m = Value(mij, arb[nod]) < Value(mij, line);
if (!m)
swap(arb[nod], line);
if (a + 1 == b) return;
if (m != st) Update(2*nod, a, mij, line);
else Update(2*nod+1, mij, b, line);
}
LL Best (int nod, int a, int b, int x) {
LL val = Value(1LL * x, arb[nod]);
int mij = (a + b) / 2;
if (b - a == 1)
return val;
if (x < mij) return min(val, Best(2*nod, a, mij, x));
else return min(val, Best(2*nod+1, mij, b, x));
}
public:
void Init (int Size) {
sz = Size;
arb.resize(4*Size + 4);
for (int i = 1; i <= 4 * sz; ++ i ) {
arb[i] = {0, INF};
}
}
void AddLine (LL fr, LL sec) {
Update(1, 0, sz, {fr, sec});
}
LL Answer (int ind) {
return Best(1, 0, sz, ind);
}
};
int N, M;
LL X, W, T;
PLL refill[NMAX];
PLL pass[NMAX];
LL dp[NMAX];
LL spC[NMAX];
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> X >> N >> M >> W >> T;
for (int i = 1; i <= N; ++ i ) {
LL s;
cin >> s;
refill[i].first = s % T;
refill[i].second = s / T;
}
++ N;
refill[N].first = X % T;
refill[N].second = X / T;
for (int i = 1; i <= M; ++ i )
cin >> pass[i].first >> pass[i].second;
sort(refill + 1, refill + N + 1);
sort(pass + 1, pass + M + 1);
for (int i = 1; i <= M; ++ i )
spC[i] = spC[i-1] + pass[i].second;
}
void Solve () {
LiChao Tree;
Tree.Init(M);
int unused = N;
for (int i = M; i >= 1; -- i ) {
for (; unused >= 1; -- unused ) {
if (pass[i].first >= refill[unused].first) break;
LL m = - W * refill[unused].second;
LL n = W * 1LL * (i + 1) * refill[unused].second + spC[i] + dp[i+1];
Tree.AddLine(m, n);
}
dp[i] = dp[i+1] + W * (X / T + (pass[i].first < X % T));
dp[i] = min(dp[i], Tree.Answer(i) - spC[i-1]);
}
cout << dp[1] + W * (X / T + 1) << '\n';
}
int main () {
Read();
Solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 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 |
0 ms |
336 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 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 |
0 ms |
336 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
2 ms |
596 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
40 |
Correct |
2 ms |
596 KB |
Output is correct |
41 |
Correct |
2 ms |
596 KB |
Output is correct |
42 |
Correct |
2 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
596 KB |
Output is correct |
44 |
Correct |
2 ms |
600 KB |
Output is correct |
45 |
Correct |
2 ms |
596 KB |
Output is correct |
46 |
Correct |
2 ms |
596 KB |
Output is correct |
47 |
Correct |
2 ms |
596 KB |
Output is correct |
48 |
Correct |
2 ms |
604 KB |
Output is correct |
49 |
Correct |
2 ms |
596 KB |
Output is correct |
50 |
Correct |
2 ms |
596 KB |
Output is correct |
51 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 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 |
0 ms |
336 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
2 ms |
596 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
40 |
Correct |
2 ms |
596 KB |
Output is correct |
41 |
Correct |
2 ms |
596 KB |
Output is correct |
42 |
Correct |
2 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
596 KB |
Output is correct |
44 |
Correct |
2 ms |
600 KB |
Output is correct |
45 |
Correct |
2 ms |
596 KB |
Output is correct |
46 |
Correct |
2 ms |
596 KB |
Output is correct |
47 |
Correct |
2 ms |
596 KB |
Output is correct |
48 |
Correct |
2 ms |
604 KB |
Output is correct |
49 |
Correct |
2 ms |
596 KB |
Output is correct |
50 |
Correct |
2 ms |
596 KB |
Output is correct |
51 |
Correct |
2 ms |
596 KB |
Output is correct |
52 |
Correct |
145 ms |
27856 KB |
Output is correct |
53 |
Correct |
119 ms |
28004 KB |
Output is correct |
54 |
Correct |
135 ms |
27112 KB |
Output is correct |
55 |
Correct |
142 ms |
27304 KB |
Output is correct |
56 |
Correct |
150 ms |
27688 KB |
Output is correct |
57 |
Correct |
143 ms |
27388 KB |
Output is correct |
58 |
Correct |
157 ms |
27888 KB |
Output is correct |
59 |
Correct |
163 ms |
27296 KB |
Output is correct |
60 |
Correct |
139 ms |
27108 KB |
Output is correct |
61 |
Correct |
133 ms |
27228 KB |
Output is correct |
62 |
Correct |
159 ms |
27268 KB |
Output is correct |
63 |
Correct |
105 ms |
26212 KB |
Output is correct |
64 |
Correct |
100 ms |
28092 KB |
Output is correct |
65 |
Correct |
141 ms |
27928 KB |
Output is correct |
66 |
Correct |
142 ms |
27888 KB |
Output is correct |
67 |
Correct |
123 ms |
27924 KB |
Output is correct |
68 |
Correct |
126 ms |
27912 KB |
Output is correct |
69 |
Correct |
142 ms |
27724 KB |
Output is correct |
70 |
Correct |
151 ms |
27672 KB |
Output is correct |
71 |
Correct |
141 ms |
27636 KB |
Output is correct |
72 |
Correct |
144 ms |
27688 KB |
Output is correct |
73 |
Correct |
152 ms |
27680 KB |
Output is correct |
74 |
Correct |
154 ms |
27792 KB |
Output is correct |
75 |
Correct |
141 ms |
27852 KB |
Output is correct |
76 |
Correct |
148 ms |
27840 KB |
Output is correct |
77 |
Correct |
154 ms |
27604 KB |
Output is correct |
78 |
Correct |
145 ms |
27884 KB |
Output is correct |
79 |
Correct |
141 ms |
27276 KB |
Output is correct |
80 |
Correct |
135 ms |
27304 KB |
Output is correct |