#include <stdio.h>
#include <algorithm>
#define MAXN 200000
#define INFINIT 1000000000000000000
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 {
long long a, b;
inline long long eval(long long x) {
return a * x + b;
}
};
struct Node {
Node *st, *dr;
Line val;
Node(Line val) {
st = dr = nullptr;
this->val = val;
}
};
void update(Node *&node, int left, int right, Line val) {
int 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);
}
}
}
long long query(Node *&node, int left, int right, long long pos) {
int middle;
long long 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 {
int val, tip;
long long aux;
} 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, t, w, i, j;
long long x;
scanf("%lld%d%d%d%d", &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("%d%lld", &v[i].val, &v[i].aux);
v[i].tip = 1;
}
m++;
v[n + m] = (struct Arbore){.val = (int)(x % t), .tip = 0, .aux = x};
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++) {
if(v[i].tip == 0) {
dp[i] = INFINIT;
for(j = 0; j < i; j++) {
dp[i] = min(dp[i], dp[j] + sp[i] - sp[j] + (v[i].aux
- v[i].val) / t * 1LL * w * (cnt[i] - cnt[j]));
}
} else {
dp[i] = dp[i - 1] + 1LL * w * (x / t + (v[i].val <= x % t));
}
}
// adaug la final si pentru sofer
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%d", &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("%d%lld", &v[i].val, &v[i].aux);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4496 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4528 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
0 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4528 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4496 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4528 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
0 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4528 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
0 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4532 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4496 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4528 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
0 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4528 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
0 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4532 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
7 ms |
4444 KB |
Output is correct |
39 |
Correct |
6 ms |
4628 KB |
Output is correct |
40 |
Correct |
6 ms |
4444 KB |
Output is correct |
41 |
Correct |
7 ms |
4444 KB |
Output is correct |
42 |
Correct |
6 ms |
4540 KB |
Output is correct |
43 |
Correct |
4 ms |
4612 KB |
Output is correct |
44 |
Correct |
6 ms |
4440 KB |
Output is correct |
45 |
Correct |
6 ms |
4444 KB |
Output is correct |
46 |
Correct |
6 ms |
4560 KB |
Output is correct |
47 |
Correct |
6 ms |
4632 KB |
Output is correct |
48 |
Correct |
6 ms |
4444 KB |
Output is correct |
49 |
Correct |
6 ms |
4444 KB |
Output is correct |
50 |
Correct |
6 ms |
4620 KB |
Output is correct |
51 |
Correct |
6 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4496 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4528 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
0 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4528 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
0 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4532 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
7 ms |
4444 KB |
Output is correct |
39 |
Correct |
6 ms |
4628 KB |
Output is correct |
40 |
Correct |
6 ms |
4444 KB |
Output is correct |
41 |
Correct |
7 ms |
4444 KB |
Output is correct |
42 |
Correct |
6 ms |
4540 KB |
Output is correct |
43 |
Correct |
4 ms |
4612 KB |
Output is correct |
44 |
Correct |
6 ms |
4440 KB |
Output is correct |
45 |
Correct |
6 ms |
4444 KB |
Output is correct |
46 |
Correct |
6 ms |
4560 KB |
Output is correct |
47 |
Correct |
6 ms |
4632 KB |
Output is correct |
48 |
Correct |
6 ms |
4444 KB |
Output is correct |
49 |
Correct |
6 ms |
4444 KB |
Output is correct |
50 |
Correct |
6 ms |
4620 KB |
Output is correct |
51 |
Correct |
6 ms |
4444 KB |
Output is correct |
52 |
Execution timed out |
2061 ms |
18520 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |