#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, m, a[310000], b[310000];
bool can (ll v) {
__int128_t now = 0;
for (int i = 1; i <= n; i++) {
ll inclass = (v + a[i] - 1) / a[i];
if (inclass == m) continue;
if (inclass < m) now += m - inclass;
else {
ll z = v - m * a[i];
now -= (z + b[i] - 1) / b[i];
}
}
return now >= 0;}
int main () {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
ll z = LLONG_MAX;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
cin >> b[i];
a[i] = max(a[i], b[i]);
z= min(z, a[i]);
}
ll l = 0, r = 11e17;
while (l + 10 < r) {
ll mid = (l + r) / 2;
if (can(mid)) l = mid;
else r = mid;
}
while (can(l + 1)) l++;
// cout << can(19) << '\n';
cout << l << '\n';
return 0;}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
4 ms |
2392 KB |
Output is correct |
11 |
Correct |
203 ms |
5200 KB |
Output is correct |
12 |
Correct |
208 ms |
5208 KB |
Output is correct |
13 |
Correct |
209 ms |
5212 KB |
Output is correct |
14 |
Correct |
252 ms |
5212 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
327 ms |
6392 KB |
Output is correct |
17 |
Correct |
223 ms |
11600 KB |
Output is correct |
18 |
Correct |
207 ms |
11084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
327 ms |
6392 KB |
Output is correct |
3 |
Correct |
223 ms |
11600 KB |
Output is correct |
4 |
Correct |
207 ms |
11084 KB |
Output is correct |
5 |
Correct |
1 ms |
2592 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2392 KB |
Output is correct |
13 |
Correct |
108 ms |
4728 KB |
Output is correct |
14 |
Correct |
71 ms |
4952 KB |
Output is correct |
15 |
Correct |
56 ms |
4732 KB |
Output is correct |
16 |
Correct |
45 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
6 ms |
2392 KB |
Output is correct |
23 |
Correct |
5 ms |
2524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
4 ms |
2392 KB |
Output is correct |
11 |
Correct |
203 ms |
5200 KB |
Output is correct |
12 |
Correct |
208 ms |
5208 KB |
Output is correct |
13 |
Correct |
209 ms |
5212 KB |
Output is correct |
14 |
Correct |
252 ms |
5212 KB |
Output is correct |
15 |
Correct |
1 ms |
2592 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2392 KB |
Output is correct |
23 |
Correct |
108 ms |
4728 KB |
Output is correct |
24 |
Correct |
71 ms |
4952 KB |
Output is correct |
25 |
Correct |
56 ms |
4732 KB |
Output is correct |
26 |
Correct |
45 ms |
4696 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
0 ms |
2644 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
6 ms |
2392 KB |
Output is correct |
33 |
Correct |
5 ms |
2524 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
327 ms |
6392 KB |
Output is correct |
36 |
Correct |
223 ms |
11600 KB |
Output is correct |
37 |
Correct |
207 ms |
11084 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2392 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
5 ms |
2648 KB |
Output is correct |
46 |
Correct |
7 ms |
2652 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
39 ms |
5728 KB |
Output is correct |
49 |
Correct |
1 ms |
2516 KB |
Output is correct |
50 |
Correct |
1 ms |
2400 KB |
Output is correct |
51 |
Correct |
4 ms |
2396 KB |
Output is correct |
52 |
Correct |
0 ms |
2400 KB |
Output is correct |
53 |
Correct |
1 ms |
2400 KB |
Output is correct |
54 |
Correct |
1 ms |
2728 KB |
Output is correct |
55 |
Correct |
114 ms |
7512 KB |
Output is correct |
56 |
Correct |
71 ms |
6004 KB |
Output is correct |
57 |
Correct |
86 ms |
5964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2592 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2392 KB |
Output is correct |
9 |
Correct |
108 ms |
4728 KB |
Output is correct |
10 |
Correct |
71 ms |
4952 KB |
Output is correct |
11 |
Correct |
56 ms |
4732 KB |
Output is correct |
12 |
Correct |
45 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
6 ms |
2392 KB |
Output is correct |
19 |
Correct |
5 ms |
2524 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
327 ms |
6392 KB |
Output is correct |
22 |
Correct |
223 ms |
11600 KB |
Output is correct |
23 |
Correct |
207 ms |
11084 KB |
Output is correct |
24 |
Correct |
35 ms |
5472 KB |
Output is correct |
25 |
Correct |
113 ms |
7516 KB |
Output is correct |
26 |
Correct |
25 ms |
5216 KB |
Output is correct |
27 |
Correct |
206 ms |
11032 KB |
Output is correct |
28 |
Correct |
224 ms |
11044 KB |
Output is correct |
29 |
Correct |
219 ms |
11028 KB |
Output is correct |
30 |
Correct |
221 ms |
10832 KB |
Output is correct |
31 |
Correct |
203 ms |
11032 KB |
Output is correct |
32 |
Correct |
324 ms |
6248 KB |
Output is correct |
33 |
Correct |
246 ms |
11488 KB |
Output is correct |
34 |
Correct |
337 ms |
6396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
4 ms |
2392 KB |
Output is correct |
11 |
Correct |
203 ms |
5200 KB |
Output is correct |
12 |
Correct |
208 ms |
5208 KB |
Output is correct |
13 |
Correct |
209 ms |
5212 KB |
Output is correct |
14 |
Correct |
252 ms |
5212 KB |
Output is correct |
15 |
Correct |
1 ms |
2592 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2392 KB |
Output is correct |
23 |
Correct |
108 ms |
4728 KB |
Output is correct |
24 |
Correct |
71 ms |
4952 KB |
Output is correct |
25 |
Correct |
56 ms |
4732 KB |
Output is correct |
26 |
Correct |
45 ms |
4696 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
0 ms |
2644 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
6 ms |
2392 KB |
Output is correct |
33 |
Correct |
5 ms |
2524 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
0 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2392 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
5 ms |
2648 KB |
Output is correct |
42 |
Correct |
7 ms |
2652 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
39 ms |
5728 KB |
Output is correct |
45 |
Correct |
1 ms |
2516 KB |
Output is correct |
46 |
Correct |
1 ms |
2400 KB |
Output is correct |
47 |
Correct |
4 ms |
2396 KB |
Output is correct |
48 |
Correct |
0 ms |
2400 KB |
Output is correct |
49 |
Correct |
1 ms |
2400 KB |
Output is correct |
50 |
Correct |
1 ms |
2728 KB |
Output is correct |
51 |
Correct |
114 ms |
7512 KB |
Output is correct |
52 |
Correct |
71 ms |
6004 KB |
Output is correct |
53 |
Correct |
86 ms |
5964 KB |
Output is correct |
54 |
Correct |
35 ms |
5472 KB |
Output is correct |
55 |
Correct |
113 ms |
7516 KB |
Output is correct |
56 |
Correct |
25 ms |
5216 KB |
Output is correct |
57 |
Correct |
206 ms |
11032 KB |
Output is correct |
58 |
Correct |
224 ms |
11044 KB |
Output is correct |
59 |
Correct |
219 ms |
11028 KB |
Output is correct |
60 |
Correct |
221 ms |
10832 KB |
Output is correct |
61 |
Correct |
203 ms |
11032 KB |
Output is correct |
62 |
Correct |
324 ms |
6248 KB |
Output is correct |
63 |
Correct |
246 ms |
11488 KB |
Output is correct |
64 |
Correct |
337 ms |
6396 KB |
Output is correct |
65 |
Correct |
1 ms |
2392 KB |
Output is correct |
66 |
Correct |
327 ms |
6392 KB |
Output is correct |
67 |
Correct |
223 ms |
11600 KB |
Output is correct |
68 |
Correct |
207 ms |
11084 KB |
Output is correct |
69 |
Correct |
27 ms |
5220 KB |
Output is correct |
70 |
Correct |
7 ms |
2664 KB |
Output is correct |
71 |
Correct |
1 ms |
2516 KB |
Output is correct |
72 |
Correct |
33 ms |
5472 KB |
Output is correct |
73 |
Correct |
8 ms |
2656 KB |
Output is correct |
74 |
Correct |
1 ms |
2400 KB |
Output is correct |
75 |
Correct |
214 ms |
11024 KB |
Output is correct |
76 |
Correct |
221 ms |
10948 KB |
Output is correct |
77 |
Correct |
226 ms |
11036 KB |
Output is correct |
78 |
Correct |
239 ms |
10848 KB |
Output is correct |
79 |
Correct |
248 ms |
10896 KB |
Output is correct |
80 |
Correct |
227 ms |
11240 KB |
Output is correct |
81 |
Correct |
234 ms |
8932 KB |
Output is correct |
82 |
Correct |
261 ms |
9052 KB |
Output is correct |