#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 {
ll l, r; Line v;
LiChaoTree *L = NULL, *R = NULL;
LiChaoTree(ll lv, ll rv) : l(lv), r(rv) {}
void insert(Line x) {
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(m, r))->insert(x):
(L ? : L = new LiChaoTree(l, m))->insert(x);
}
ll operator()(const ll &x) {
if(r - l < 2) return v(x);
ll m = (l + r) >> 1;
return x < m ? max(v(x), L ? (*L)(x) : 0):
max(v(x), R ? (*R)(x) : 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(0, X+1);
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));
} 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});
}
cout << int64_t(ext - dp);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 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 |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 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 |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
328 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 |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
580 KB |
Output is correct |
30 |
Correct |
1 ms |
468 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 |
340 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 |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 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 |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
328 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 |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
580 KB |
Output is correct |
30 |
Correct |
1 ms |
468 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 |
340 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 |
4 ms |
596 KB |
Output is correct |
39 |
Correct |
3 ms |
596 KB |
Output is correct |
40 |
Correct |
3 ms |
724 KB |
Output is correct |
41 |
Correct |
4 ms |
724 KB |
Output is correct |
42 |
Correct |
4 ms |
852 KB |
Output is correct |
43 |
Correct |
3 ms |
728 KB |
Output is correct |
44 |
Correct |
6 ms |
3796 KB |
Output is correct |
45 |
Correct |
4 ms |
636 KB |
Output is correct |
46 |
Correct |
3 ms |
852 KB |
Output is correct |
47 |
Correct |
2 ms |
464 KB |
Output is correct |
48 |
Correct |
4 ms |
724 KB |
Output is correct |
49 |
Correct |
3 ms |
468 KB |
Output is correct |
50 |
Correct |
3 ms |
596 KB |
Output is correct |
51 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 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 |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
328 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 |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
580 KB |
Output is correct |
30 |
Correct |
1 ms |
468 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 |
340 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 |
4 ms |
596 KB |
Output is correct |
39 |
Correct |
3 ms |
596 KB |
Output is correct |
40 |
Correct |
3 ms |
724 KB |
Output is correct |
41 |
Correct |
4 ms |
724 KB |
Output is correct |
42 |
Correct |
4 ms |
852 KB |
Output is correct |
43 |
Correct |
3 ms |
728 KB |
Output is correct |
44 |
Correct |
6 ms |
3796 KB |
Output is correct |
45 |
Correct |
4 ms |
636 KB |
Output is correct |
46 |
Correct |
3 ms |
852 KB |
Output is correct |
47 |
Correct |
2 ms |
464 KB |
Output is correct |
48 |
Correct |
4 ms |
724 KB |
Output is correct |
49 |
Correct |
3 ms |
468 KB |
Output is correct |
50 |
Correct |
3 ms |
596 KB |
Output is correct |
51 |
Correct |
3 ms |
596 KB |
Output is correct |
52 |
Correct |
370 ms |
19440 KB |
Output is correct |
53 |
Correct |
316 ms |
19376 KB |
Output is correct |
54 |
Correct |
371 ms |
48088 KB |
Output is correct |
55 |
Correct |
391 ms |
43260 KB |
Output is correct |
56 |
Correct |
395 ms |
36508 KB |
Output is correct |
57 |
Correct |
389 ms |
102048 KB |
Output is correct |
58 |
Correct |
371 ms |
19276 KB |
Output is correct |
59 |
Correct |
376 ms |
40916 KB |
Output is correct |
60 |
Correct |
371 ms |
42276 KB |
Output is correct |
61 |
Correct |
381 ms |
43128 KB |
Output is correct |
62 |
Correct |
390 ms |
52776 KB |
Output is correct |
63 |
Correct |
317 ms |
47948 KB |
Output is correct |
64 |
Correct |
246 ms |
19048 KB |
Output is correct |
65 |
Correct |
293 ms |
19216 KB |
Output is correct |
66 |
Correct |
287 ms |
18940 KB |
Output is correct |
67 |
Correct |
326 ms |
19372 KB |
Output is correct |
68 |
Correct |
379 ms |
19344 KB |
Output is correct |
69 |
Correct |
382 ms |
19404 KB |
Output is correct |
70 |
Correct |
366 ms |
19332 KB |
Output is correct |
71 |
Correct |
367 ms |
19348 KB |
Output is correct |
72 |
Correct |
382 ms |
19416 KB |
Output is correct |
73 |
Correct |
370 ms |
19424 KB |
Output is correct |
74 |
Correct |
383 ms |
19152 KB |
Output is correct |
75 |
Correct |
374 ms |
19020 KB |
Output is correct |
76 |
Correct |
373 ms |
18944 KB |
Output is correct |
77 |
Correct |
378 ms |
19020 KB |
Output is correct |
78 |
Correct |
409 ms |
19536 KB |
Output is correct |
79 |
Correct |
353 ms |
19260 KB |
Output is correct |
80 |
Correct |
370 ms |
19380 KB |
Output is correct |