#include <bits/stdc++.h>
using namespace std;
using ll = __int128;
using i64 = int64_t;
const ll INF = 1e18;
const int SZ = 2e5+1;
struct Line {
ll m {}, c {};
ll operator()(const ll &x) { return m * x + c; }
};
struct LiChaoTree {
Line v;
LiChaoTree *L = NULL, *R = NULL;
void insert(Line x, ll l, ll r) {
ll m = (l + r) >> 1;
if(v(m) < x(m)) swap(v, x);
if(r - l < 2) return;
x.m > v.m ? (R ? : R = new LiChaoTree)->insert(x, m, r):
(L ? : L = new LiChaoTree)->insert(x, l, m);
}
ll operator()(const ll &x, ll l, ll r) {
if(r - l < 2) return v(x);
ll m = (l + r) >> 1;
return x < m ? max(v(x), L ? (*L)(x, l, m) : 0):
max(v(x), R ? (*R)(x, m, r) : 0);
}
};
i64 N, M, X, W, T, S[SZ], D[SZ], C[SZ];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> X >> N >> M >> W >> T;
vector<pair<ll, int>> a(N+M+1);
for(int i = 0; i < N; ++i) {
cin >> S[i];
a[i+0] = {S[i] % T, i};
}
a[N] = {X % T, N};
S[N++] = X;
for(int i = 0; i < M; ++i) {
cin >> D[i] >> C[i];
a[i+N] = {D[i] % T, i + N};
}
sort(begin(a), end(a), [](const auto &i, const auto &j) {
return i.first < j.first;
});
LiChaoTree lct;
ll cost {}, dp {}, cnt {}, ext = ll((X - ll(1)) / T + 1) * ll(W);
for(int i = 1; i <= N + M; ++i) {
int c = a[i-1].second;
if(c < N) {
ll f = (S[c] - ll(1)) / T;
dp = max(dp, cost - f * cnt * ll(W) + lct(f, 0, X + 1));
} else {
c -= N; ++cnt;
ll total = ((X - ll(1)) / T) + (D[c] < (X % T));
ext += total * ll(W);
cost += total * ll(W) - ll(C[c]);
}
lct.insert(Line{cnt * ll(W), dp - cost}, 0, X + 1);
}
cout << int64_t(ext - dp);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 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 |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
324 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 |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 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 |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
324 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 |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 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 |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
452 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
33 |
Correct |
1 ms |
328 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 |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 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 |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
324 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 |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 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 |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
452 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
33 |
Correct |
1 ms |
328 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 |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
3 ms |
596 KB |
Output is correct |
39 |
Correct |
3 ms |
596 KB |
Output is correct |
40 |
Correct |
3 ms |
592 KB |
Output is correct |
41 |
Correct |
3 ms |
596 KB |
Output is correct |
42 |
Correct |
4 ms |
772 KB |
Output is correct |
43 |
Correct |
3 ms |
724 KB |
Output is correct |
44 |
Correct |
5 ms |
2772 KB |
Output is correct |
45 |
Correct |
3 ms |
596 KB |
Output is correct |
46 |
Correct |
2 ms |
724 KB |
Output is correct |
47 |
Correct |
2 ms |
468 KB |
Output is correct |
48 |
Correct |
4 ms |
596 KB |
Output is correct |
49 |
Correct |
3 ms |
468 KB |
Output is correct |
50 |
Correct |
3 ms |
592 KB |
Output is correct |
51 |
Correct |
3 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 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 |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
324 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 |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 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 |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
452 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
33 |
Correct |
1 ms |
328 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 |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
3 ms |
596 KB |
Output is correct |
39 |
Correct |
3 ms |
596 KB |
Output is correct |
40 |
Correct |
3 ms |
592 KB |
Output is correct |
41 |
Correct |
3 ms |
596 KB |
Output is correct |
42 |
Correct |
4 ms |
772 KB |
Output is correct |
43 |
Correct |
3 ms |
724 KB |
Output is correct |
44 |
Correct |
5 ms |
2772 KB |
Output is correct |
45 |
Correct |
3 ms |
596 KB |
Output is correct |
46 |
Correct |
2 ms |
724 KB |
Output is correct |
47 |
Correct |
2 ms |
468 KB |
Output is correct |
48 |
Correct |
4 ms |
596 KB |
Output is correct |
49 |
Correct |
3 ms |
468 KB |
Output is correct |
50 |
Correct |
3 ms |
592 KB |
Output is correct |
51 |
Correct |
3 ms |
508 KB |
Output is correct |
52 |
Correct |
360 ms |
18192 KB |
Output is correct |
53 |
Correct |
317 ms |
18104 KB |
Output is correct |
54 |
Correct |
359 ms |
37216 KB |
Output is correct |
55 |
Correct |
362 ms |
33992 KB |
Output is correct |
56 |
Correct |
382 ms |
29520 KB |
Output is correct |
57 |
Correct |
359 ms |
73188 KB |
Output is correct |
58 |
Correct |
349 ms |
17928 KB |
Output is correct |
59 |
Correct |
363 ms |
32380 KB |
Output is correct |
60 |
Correct |
358 ms |
33648 KB |
Output is correct |
61 |
Correct |
372 ms |
34000 KB |
Output is correct |
62 |
Correct |
366 ms |
40292 KB |
Output is correct |
63 |
Correct |
311 ms |
37168 KB |
Output is correct |
64 |
Correct |
262 ms |
17708 KB |
Output is correct |
65 |
Correct |
310 ms |
17976 KB |
Output is correct |
66 |
Correct |
285 ms |
17784 KB |
Output is correct |
67 |
Correct |
312 ms |
18084 KB |
Output is correct |
68 |
Correct |
366 ms |
18028 KB |
Output is correct |
69 |
Correct |
359 ms |
18124 KB |
Output is correct |
70 |
Correct |
356 ms |
18124 KB |
Output is correct |
71 |
Correct |
355 ms |
18072 KB |
Output is correct |
72 |
Correct |
362 ms |
18144 KB |
Output is correct |
73 |
Correct |
375 ms |
17996 KB |
Output is correct |
74 |
Correct |
362 ms |
18012 KB |
Output is correct |
75 |
Correct |
364 ms |
17776 KB |
Output is correct |
76 |
Correct |
345 ms |
17796 KB |
Output is correct |
77 |
Correct |
429 ms |
17912 KB |
Output is correct |
78 |
Correct |
394 ms |
18172 KB |
Output is correct |
79 |
Correct |
354 ms |
18088 KB |
Output is correct |
80 |
Correct |
377 ms |
17964 KB |
Output is correct |