#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
cin.tie(0); ios_base::sync_with_stdio(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];
for(int i = 0; i < n; i++) a[i] = max(a[i], b[i]);
auto ok = [&](ll x) -> bool {
ll left = n * m;
for(int i = 0; i < n; i++) {
left -= min(m, (x + a[i] - 1) / a[i]);
if(x - a[i] * m > 0) left -= (x - a[i] * m + b[i] - 1) / b[i];
if(left < 0) return 0;
}
return 1;
};
ll l = 0, r = 2e18, ans = 0;
while(l <= r) {
ll mid = (l + r) / 2;
if(ok(mid)) {
l = mid + 1, ans = mid;
} else {
r = mid - 1;
}
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
113 ms |
5004 KB |
Output is correct |
12 |
Correct |
95 ms |
4948 KB |
Output is correct |
13 |
Correct |
111 ms |
5008 KB |
Output is correct |
14 |
Correct |
80 ms |
5008 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
40 ms |
4948 KB |
Output is correct |
17 |
Correct |
124 ms |
4948 KB |
Output is correct |
18 |
Correct |
93 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
40 ms |
4948 KB |
Output is correct |
3 |
Correct |
124 ms |
4948 KB |
Output is correct |
4 |
Correct |
93 ms |
4948 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
1 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 |
51 ms |
2644 KB |
Output is correct |
14 |
Correct |
35 ms |
1876 KB |
Output is correct |
15 |
Correct |
23 ms |
1492 KB |
Output is correct |
16 |
Correct |
21 ms |
1236 KB |
Output is correct |
17 |
Correct |
1 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 |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
113 ms |
5004 KB |
Output is correct |
12 |
Correct |
95 ms |
4948 KB |
Output is correct |
13 |
Correct |
111 ms |
5008 KB |
Output is correct |
14 |
Correct |
80 ms |
5008 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 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 |
1 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 |
51 ms |
2644 KB |
Output is correct |
24 |
Correct |
35 ms |
1876 KB |
Output is correct |
25 |
Correct |
23 ms |
1492 KB |
Output is correct |
26 |
Correct |
21 ms |
1236 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
2 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 |
40 ms |
4948 KB |
Output is correct |
36 |
Correct |
124 ms |
4948 KB |
Output is correct |
37 |
Correct |
93 ms |
4948 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 |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
320 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
3 ms |
468 KB |
Output is correct |
46 |
Correct |
4 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
19 ms |
2124 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
3 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
320 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
52 ms |
5528 KB |
Output is correct |
56 |
Correct |
40 ms |
3148 KB |
Output is correct |
57 |
Correct |
32 ms |
3160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
51 ms |
2644 KB |
Output is correct |
10 |
Correct |
35 ms |
1876 KB |
Output is correct |
11 |
Correct |
23 ms |
1492 KB |
Output is correct |
12 |
Correct |
21 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
2 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 |
40 ms |
4948 KB |
Output is correct |
22 |
Correct |
124 ms |
4948 KB |
Output is correct |
23 |
Correct |
93 ms |
4948 KB |
Output is correct |
24 |
Correct |
35 ms |
980 KB |
Output is correct |
25 |
Correct |
74 ms |
2420 KB |
Output is correct |
26 |
Correct |
13 ms |
724 KB |
Output is correct |
27 |
Correct |
93 ms |
4948 KB |
Output is correct |
28 |
Correct |
115 ms |
4948 KB |
Output is correct |
29 |
Correct |
106 ms |
4948 KB |
Output is correct |
30 |
Correct |
131 ms |
4948 KB |
Output is correct |
31 |
Correct |
210 ms |
5008 KB |
Output is correct |
32 |
Correct |
154 ms |
5012 KB |
Output is correct |
33 |
Correct |
347 ms |
4948 KB |
Output is correct |
34 |
Correct |
172 ms |
5004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
113 ms |
5004 KB |
Output is correct |
12 |
Correct |
95 ms |
4948 KB |
Output is correct |
13 |
Correct |
111 ms |
5008 KB |
Output is correct |
14 |
Correct |
80 ms |
5008 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 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 |
1 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 |
51 ms |
2644 KB |
Output is correct |
24 |
Correct |
35 ms |
1876 KB |
Output is correct |
25 |
Correct |
23 ms |
1492 KB |
Output is correct |
26 |
Correct |
21 ms |
1236 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
2 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 |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
320 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
3 ms |
468 KB |
Output is correct |
42 |
Correct |
4 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
19 ms |
2124 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
3 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
320 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
52 ms |
5528 KB |
Output is correct |
52 |
Correct |
40 ms |
3148 KB |
Output is correct |
53 |
Correct |
32 ms |
3160 KB |
Output is correct |
54 |
Correct |
35 ms |
980 KB |
Output is correct |
55 |
Correct |
74 ms |
2420 KB |
Output is correct |
56 |
Correct |
13 ms |
724 KB |
Output is correct |
57 |
Correct |
93 ms |
4948 KB |
Output is correct |
58 |
Correct |
115 ms |
4948 KB |
Output is correct |
59 |
Correct |
106 ms |
4948 KB |
Output is correct |
60 |
Correct |
131 ms |
4948 KB |
Output is correct |
61 |
Correct |
210 ms |
5008 KB |
Output is correct |
62 |
Correct |
154 ms |
5012 KB |
Output is correct |
63 |
Correct |
347 ms |
4948 KB |
Output is correct |
64 |
Correct |
172 ms |
5004 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
40 ms |
4948 KB |
Output is correct |
67 |
Correct |
124 ms |
4948 KB |
Output is correct |
68 |
Correct |
93 ms |
4948 KB |
Output is correct |
69 |
Correct |
25 ms |
1352 KB |
Output is correct |
70 |
Correct |
7 ms |
600 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
34 ms |
1736 KB |
Output is correct |
73 |
Correct |
8 ms |
596 KB |
Output is correct |
74 |
Correct |
1 ms |
332 KB |
Output is correct |
75 |
Correct |
120 ms |
10700 KB |
Output is correct |
76 |
Correct |
138 ms |
10880 KB |
Output is correct |
77 |
Correct |
139 ms |
10812 KB |
Output is correct |
78 |
Correct |
174 ms |
10756 KB |
Output is correct |
79 |
Correct |
255 ms |
10804 KB |
Output is correct |
80 |
Correct |
232 ms |
10752 KB |
Output is correct |
81 |
Correct |
339 ms |
8824 KB |
Output is correct |
82 |
Correct |
209 ms |
8820 KB |
Output is correct |