#include <stdio.h>
#include <algorithm>
#define MAXN 200000
#define INFINIT 2000000000000000000
static inline long long min(long long a, long long b) {
return a < b ? a : b;
}
static inline long long max(long long a, long long b) {
return a > b ? a : b;
}
// lichao incoming
struct Line {
int a;
long long b;
inline __int128 eval(__int128 x) {
return a * x + b;
}
};
struct Node {
Node *st, *dr;
Line val;
Node(Line val) {
st = dr = nullptr;
this->val = val;
}
} *lichao = nullptr;
void update(Node *&node, long long left, long long right, Line val) {
long long middle;
if(node == nullptr) {
node = new Node(val);
} else {
middle = (left + right) / 2;
if(node->val.eval(middle) > val.eval(middle)) {
std::swap(node->val, val);
}
if(node->val.eval(left) > val.eval(left)) {
update(node->st, left, middle, val);
}
if(node->val.eval(right) > val.eval(right)) {
update(node->dr, middle + 1, right, val);
}
}
}
__int128 query(Node *&node, long long left, long long right,
long long pos) {
long long middle;
__int128 ans;
if(node == nullptr) {
return INFINIT;
}
middle = (left + right) / 2;
ans = node->val.eval(pos);
if(pos <= middle) {
ans = min(ans, query(node->st, left, middle, pos));
} else {
ans = min(ans, query(node->dr, middle + 1, right, pos));
}
return ans;
}
struct Arbore {
long long val, aux;
int tip;
} v[2 * MAXN + 2];
static inline int compar(Arbore a, Arbore b) {
return a.val < b.val;
}
long long sp[2 * MAXN + 2], dp[2 * MAXN];
int cnt[2 * MAXN + 2];
int main() {
int n, m, w, i;
long long x, t, mult;
scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);
for(i = 1; i <= n; i++) {
scanf("%lld", &v[i].aux);
v[i].val = v[i].aux % t;
v[i].tip = 0;
}
for(i = n + 1; i <= n + m; i++) {
scanf("%lld%lld", &v[i].val, &v[i].aux);
v[i].tip = 1;
}
m++;
v[n + m] = (struct Arbore){.val = x % t, .aux = x, .tip = 0};
std::sort(v + 1, v + n + m + 1, compar);
for(i = 1; i <= n + m; i++) {
sp[i] = sp[i - 1] + v[i].aux * v[i].tip;
cnt[i] = cnt[i - 1] + v[i].tip;
}
dp[0] = 1LL * (x / t + 1) * w;
for(i = 1; i <= n + m; i++) {
update(lichao, 0, INFINIT, (struct Line){.a = -cnt[i - 1],
.b = dp[i - 1] - sp[i - 1]});
if(v[i].tip == 0) {
mult = 1LL * (v[i].aux - v[i].val) / t * w;
dp[i] = sp[i] + mult * cnt[i] + (long long)query(lichao, 0,
INFINIT, mult);
} else {
dp[i] = dp[i - 1] + 1LL * w * (x / t + (v[i].val <= x % t));
}
}
printf("%lld\n", dp[n + m]);
return 0;
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:90:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | scanf("%lld", &v[i].aux);
| ~~~~~^~~~~~~~~~~~~~~~~~~
coach.cpp:98:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | scanf("%lld%lld", &v[i].val, &v[i].aux);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
428 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
428 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
392 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
412 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
432 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
428 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
392 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
412 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
432 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
2 ms |
536 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
2 ms |
520 KB |
Output is correct |
42 |
Correct |
2 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
2 ms |
700 KB |
Output is correct |
47 |
Correct |
1 ms |
448 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
2 ms |
604 KB |
Output is correct |
50 |
Correct |
2 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
428 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
392 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
412 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
432 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
2 ms |
536 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
2 ms |
520 KB |
Output is correct |
42 |
Correct |
2 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
2 ms |
700 KB |
Output is correct |
47 |
Correct |
1 ms |
448 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
2 ms |
604 KB |
Output is correct |
50 |
Correct |
2 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
444 KB |
Output is correct |
52 |
Correct |
143 ms |
23280 KB |
Output is correct |
53 |
Correct |
156 ms |
23324 KB |
Output is correct |
54 |
Correct |
192 ms |
22352 KB |
Output is correct |
55 |
Correct |
188 ms |
22608 KB |
Output is correct |
56 |
Correct |
161 ms |
22868 KB |
Output is correct |
57 |
Correct |
164 ms |
22608 KB |
Output is correct |
58 |
Correct |
138 ms |
23212 KB |
Output is correct |
59 |
Correct |
196 ms |
22608 KB |
Output is correct |
60 |
Correct |
195 ms |
22340 KB |
Output is correct |
61 |
Correct |
186 ms |
22492 KB |
Output is correct |
62 |
Correct |
184 ms |
22612 KB |
Output is correct |
63 |
Correct |
241 ms |
30984 KB |
Output is correct |
64 |
Correct |
192 ms |
23384 KB |
Output is correct |
65 |
Correct |
160 ms |
23376 KB |
Output is correct |
66 |
Correct |
137 ms |
23136 KB |
Output is correct |
67 |
Correct |
185 ms |
23304 KB |
Output is correct |
68 |
Correct |
167 ms |
23380 KB |
Output is correct |
69 |
Correct |
147 ms |
23124 KB |
Output is correct |
70 |
Correct |
166 ms |
23016 KB |
Output is correct |
71 |
Correct |
146 ms |
23100 KB |
Output is correct |
72 |
Correct |
148 ms |
23120 KB |
Output is correct |
73 |
Correct |
146 ms |
23120 KB |
Output is correct |
74 |
Correct |
142 ms |
23124 KB |
Output is correct |
75 |
Correct |
116 ms |
23136 KB |
Output is correct |
76 |
Correct |
114 ms |
23120 KB |
Output is correct |
77 |
Correct |
240 ms |
22868 KB |
Output is correct |
78 |
Correct |
184 ms |
23104 KB |
Output is correct |
79 |
Correct |
155 ms |
22612 KB |
Output is correct |
80 |
Correct |
142 ms |
22616 KB |
Output is correct |