#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2e5 + 2;
const int inf = 2e9;
ll C(ll a, ll b) {
if (a <= 0) return 0;
return (a + b - 1) / b;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, m;
cin >> n >> m;
vector<ll> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
auto Can = [&] (ll x) {
ll kol = 0;
for (int i = 0; i < n; i++) {
ll p = C(x, b[i]);
ll o = min(C(x, a[i]), m);
ll q = o + C(x - o * a[i], b[i]);
kol += min(p, q);
if (kol > n * m) return 0;
}
if (kol <= n * m) return 1;
return 0;
};
ll l = 1, r = 1e18, ans = 0;
while (l <= r) {
ll mid = l + r >> 1;
if (Can(mid)) {
l = mid + 1;
ans = mid;
}
else r = mid - 1;
}
cout << ans << en;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:38:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | ll mid = l + r >> 1;
| ~~^~~
# |
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 |
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 |
131 ms |
4948 KB |
Output is correct |
12 |
Correct |
137 ms |
5004 KB |
Output is correct |
13 |
Correct |
177 ms |
5008 KB |
Output is correct |
14 |
Correct |
114 ms |
4948 KB |
Output is correct |
15 |
Correct |
0 ms |
316 KB |
Output is correct |
16 |
Correct |
35 ms |
5044 KB |
Output is correct |
17 |
Correct |
152 ms |
11404 KB |
Output is correct |
18 |
Correct |
134 ms |
10700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
316 KB |
Output is correct |
2 |
Correct |
35 ms |
5044 KB |
Output is correct |
3 |
Correct |
152 ms |
11404 KB |
Output is correct |
4 |
Correct |
134 ms |
10700 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
71 ms |
2656 KB |
Output is correct |
14 |
Correct |
47 ms |
1876 KB |
Output is correct |
15 |
Correct |
34 ms |
1492 KB |
Output is correct |
16 |
Correct |
29 ms |
1236 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 |
4 ms |
468 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 |
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 |
131 ms |
4948 KB |
Output is correct |
12 |
Correct |
137 ms |
5004 KB |
Output is correct |
13 |
Correct |
177 ms |
5008 KB |
Output is correct |
14 |
Correct |
114 ms |
4948 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 |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
71 ms |
2656 KB |
Output is correct |
24 |
Correct |
47 ms |
1876 KB |
Output is correct |
25 |
Correct |
34 ms |
1492 KB |
Output is correct |
26 |
Correct |
29 ms |
1236 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 |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
316 KB |
Output is correct |
35 |
Correct |
35 ms |
5044 KB |
Output is correct |
36 |
Correct |
152 ms |
11404 KB |
Output is correct |
37 |
Correct |
134 ms |
10700 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
4 ms |
504 KB |
Output is correct |
46 |
Correct |
6 ms |
588 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
31 ms |
2012 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
4 ms |
464 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
320 KB |
Output is correct |
55 |
Correct |
93 ms |
5456 KB |
Output is correct |
56 |
Correct |
75 ms |
3156 KB |
Output is correct |
57 |
Correct |
45 ms |
3028 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
71 ms |
2656 KB |
Output is correct |
10 |
Correct |
47 ms |
1876 KB |
Output is correct |
11 |
Correct |
34 ms |
1492 KB |
Output is correct |
12 |
Correct |
29 ms |
1236 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 |
4 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
316 KB |
Output is correct |
21 |
Correct |
35 ms |
5044 KB |
Output is correct |
22 |
Correct |
152 ms |
11404 KB |
Output is correct |
23 |
Correct |
134 ms |
10700 KB |
Output is correct |
24 |
Correct |
53 ms |
1932 KB |
Output is correct |
25 |
Correct |
120 ms |
4972 KB |
Output is correct |
26 |
Correct |
22 ms |
1364 KB |
Output is correct |
27 |
Correct |
132 ms |
10700 KB |
Output is correct |
28 |
Correct |
145 ms |
10760 KB |
Output is correct |
29 |
Correct |
158 ms |
10896 KB |
Output is correct |
30 |
Correct |
202 ms |
10896 KB |
Output is correct |
31 |
Correct |
351 ms |
10700 KB |
Output is correct |
32 |
Correct |
236 ms |
6284 KB |
Output is correct |
33 |
Correct |
407 ms |
11400 KB |
Output is correct |
34 |
Correct |
249 ms |
6220 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 |
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 |
131 ms |
4948 KB |
Output is correct |
12 |
Correct |
137 ms |
5004 KB |
Output is correct |
13 |
Correct |
177 ms |
5008 KB |
Output is correct |
14 |
Correct |
114 ms |
4948 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 |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
71 ms |
2656 KB |
Output is correct |
24 |
Correct |
47 ms |
1876 KB |
Output is correct |
25 |
Correct |
34 ms |
1492 KB |
Output is correct |
26 |
Correct |
29 ms |
1236 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 |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
4 ms |
504 KB |
Output is correct |
42 |
Correct |
6 ms |
588 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
31 ms |
2012 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
4 ms |
464 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
320 KB |
Output is correct |
51 |
Correct |
93 ms |
5456 KB |
Output is correct |
52 |
Correct |
75 ms |
3156 KB |
Output is correct |
53 |
Correct |
45 ms |
3028 KB |
Output is correct |
54 |
Correct |
53 ms |
1932 KB |
Output is correct |
55 |
Correct |
120 ms |
4972 KB |
Output is correct |
56 |
Correct |
22 ms |
1364 KB |
Output is correct |
57 |
Correct |
132 ms |
10700 KB |
Output is correct |
58 |
Correct |
145 ms |
10760 KB |
Output is correct |
59 |
Correct |
158 ms |
10896 KB |
Output is correct |
60 |
Correct |
202 ms |
10896 KB |
Output is correct |
61 |
Correct |
351 ms |
10700 KB |
Output is correct |
62 |
Correct |
236 ms |
6284 KB |
Output is correct |
63 |
Correct |
407 ms |
11400 KB |
Output is correct |
64 |
Correct |
249 ms |
6220 KB |
Output is correct |
65 |
Correct |
0 ms |
316 KB |
Output is correct |
66 |
Correct |
35 ms |
5044 KB |
Output is correct |
67 |
Correct |
152 ms |
11404 KB |
Output is correct |
68 |
Correct |
134 ms |
10700 KB |
Output is correct |
69 |
Correct |
45 ms |
1464 KB |
Output is correct |
70 |
Correct |
13 ms |
564 KB |
Output is correct |
71 |
Correct |
1 ms |
316 KB |
Output is correct |
72 |
Correct |
64 ms |
1740 KB |
Output is correct |
73 |
Correct |
13 ms |
596 KB |
Output is correct |
74 |
Correct |
2 ms |
340 KB |
Output is correct |
75 |
Correct |
183 ms |
10700 KB |
Output is correct |
76 |
Correct |
210 ms |
10956 KB |
Output is correct |
77 |
Correct |
232 ms |
10768 KB |
Output is correct |
78 |
Correct |
318 ms |
10876 KB |
Output is correct |
79 |
Correct |
474 ms |
10804 KB |
Output is correct |
80 |
Correct |
459 ms |
10808 KB |
Output is correct |
81 |
Correct |
632 ms |
8908 KB |
Output is correct |
82 |
Correct |
469 ms |
8908 KB |
Output is correct |