#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
auto solve = [&]() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
a[i] = max(a[i], b[i]);
}
i64 lo = 0, hi = 2e18;
while (lo < hi) {
i64 md = lo + hi + 1 >> 1;
i64 cnt = 0;
bool ok = true;
for (int i = 0; i < n; i++) {
if (md <= 1LL * m * a[i]) {
cnt += (md + a[i] - 1) / a[i];
} else {
cnt += m + (md - 1LL * a[i] * m + b[i] - 1) / b[i];
}
if (cnt > 1LL * n * m) {
ok = false;
break;
}
}
if (ok) {
lo = md;
} else {
hi = md - 1;
}
}
cout << lo << '\n';
};
solve();
return 0;
}
Compilation message
Main.cpp: In lambda function:
Main.cpp:30:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | i64 md = lo + hi + 1 >> 1;
| ~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
95 ms |
2660 KB |
Output is correct |
12 |
Correct |
107 ms |
2644 KB |
Output is correct |
13 |
Correct |
83 ms |
2660 KB |
Output is correct |
14 |
Correct |
72 ms |
2644 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
41 ms |
3800 KB |
Output is correct |
17 |
Correct |
108 ms |
9052 KB |
Output is correct |
18 |
Correct |
101 ms |
8468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
41 ms |
3800 KB |
Output is correct |
3 |
Correct |
108 ms |
9052 KB |
Output is correct |
4 |
Correct |
101 ms |
8468 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
48 ms |
1492 KB |
Output is correct |
14 |
Correct |
30 ms |
1108 KB |
Output is correct |
15 |
Correct |
23 ms |
852 KB |
Output is correct |
16 |
Correct |
20 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
95 ms |
2660 KB |
Output is correct |
12 |
Correct |
107 ms |
2644 KB |
Output is correct |
13 |
Correct |
83 ms |
2660 KB |
Output is correct |
14 |
Correct |
72 ms |
2644 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
48 ms |
1492 KB |
Output is correct |
24 |
Correct |
30 ms |
1108 KB |
Output is correct |
25 |
Correct |
23 ms |
852 KB |
Output is correct |
26 |
Correct |
20 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
41 ms |
3800 KB |
Output is correct |
36 |
Correct |
108 ms |
9052 KB |
Output is correct |
37 |
Correct |
101 ms |
8468 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
328 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
2 ms |
340 KB |
Output is correct |
46 |
Correct |
4 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
21 ms |
1620 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
324 KB |
Output is correct |
51 |
Correct |
3 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
320 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
58 ms |
4300 KB |
Output is correct |
56 |
Correct |
32 ms |
2388 KB |
Output is correct |
57 |
Correct |
26 ms |
2372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
48 ms |
1492 KB |
Output is correct |
10 |
Correct |
30 ms |
1108 KB |
Output is correct |
11 |
Correct |
23 ms |
852 KB |
Output is correct |
12 |
Correct |
20 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
41 ms |
3800 KB |
Output is correct |
22 |
Correct |
108 ms |
9052 KB |
Output is correct |
23 |
Correct |
101 ms |
8468 KB |
Output is correct |
24 |
Correct |
33 ms |
1580 KB |
Output is correct |
25 |
Correct |
80 ms |
3972 KB |
Output is correct |
26 |
Correct |
12 ms |
1108 KB |
Output is correct |
27 |
Correct |
94 ms |
8416 KB |
Output is correct |
28 |
Correct |
102 ms |
8396 KB |
Output is correct |
29 |
Correct |
114 ms |
8416 KB |
Output is correct |
30 |
Correct |
125 ms |
8416 KB |
Output is correct |
31 |
Correct |
204 ms |
8468 KB |
Output is correct |
32 |
Correct |
102 ms |
3840 KB |
Output is correct |
33 |
Correct |
175 ms |
9048 KB |
Output is correct |
34 |
Correct |
98 ms |
3944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
95 ms |
2660 KB |
Output is correct |
12 |
Correct |
107 ms |
2644 KB |
Output is correct |
13 |
Correct |
83 ms |
2660 KB |
Output is correct |
14 |
Correct |
72 ms |
2644 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
48 ms |
1492 KB |
Output is correct |
24 |
Correct |
30 ms |
1108 KB |
Output is correct |
25 |
Correct |
23 ms |
852 KB |
Output is correct |
26 |
Correct |
20 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
328 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
2 ms |
340 KB |
Output is correct |
42 |
Correct |
4 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
21 ms |
1620 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
324 KB |
Output is correct |
47 |
Correct |
3 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
320 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
58 ms |
4300 KB |
Output is correct |
52 |
Correct |
32 ms |
2388 KB |
Output is correct |
53 |
Correct |
26 ms |
2372 KB |
Output is correct |
54 |
Correct |
33 ms |
1580 KB |
Output is correct |
55 |
Correct |
80 ms |
3972 KB |
Output is correct |
56 |
Correct |
12 ms |
1108 KB |
Output is correct |
57 |
Correct |
94 ms |
8416 KB |
Output is correct |
58 |
Correct |
102 ms |
8396 KB |
Output is correct |
59 |
Correct |
114 ms |
8416 KB |
Output is correct |
60 |
Correct |
125 ms |
8416 KB |
Output is correct |
61 |
Correct |
204 ms |
8468 KB |
Output is correct |
62 |
Correct |
102 ms |
3840 KB |
Output is correct |
63 |
Correct |
175 ms |
9048 KB |
Output is correct |
64 |
Correct |
98 ms |
3944 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
41 ms |
3800 KB |
Output is correct |
67 |
Correct |
108 ms |
9052 KB |
Output is correct |
68 |
Correct |
101 ms |
8468 KB |
Output is correct |
69 |
Correct |
22 ms |
1096 KB |
Output is correct |
70 |
Correct |
6 ms |
536 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
32 ms |
1424 KB |
Output is correct |
73 |
Correct |
7 ms |
468 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
110 ms |
8472 KB |
Output is correct |
76 |
Correct |
118 ms |
8472 KB |
Output is correct |
77 |
Correct |
118 ms |
8472 KB |
Output is correct |
78 |
Correct |
179 ms |
8472 KB |
Output is correct |
79 |
Correct |
220 ms |
8472 KB |
Output is correct |
80 |
Correct |
229 ms |
8464 KB |
Output is correct |
81 |
Correct |
170 ms |
6484 KB |
Output is correct |
82 |
Correct |
128 ms |
6488 KB |
Output is correct |