#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vei;
typedef vector<vei> vevei;
#define all(a) (a).begin(), (a).end()
#define sz(a) (int) a.size()
#define con cout << "NO\n"
#define coe cout << "YES\n";
#define str string
#define pb push_back
#define ff first
#define sc second
#define ss second
#define pii pair<int, int>
#define mxe max_element
#define mne min_element
#define stf shrink_to_fit
#define f(i, l, r) for (int i = (l); i < (r); i++)
#define double ld
#define int __int128
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n, m; cin >> n >> m;
vector<ll> a(n), b(n);
f(i, 0, n) cin >> a[i];
f(i, 0, n) cin >> b[i];
int ans = 1e18;
f(i, 0, n) {
ans = min(ans, (int)max(a[i], b[i]));
}
int L = -1, R = 1e18 + 1;
while (R - L > 1) {
int M = (L + R) / 2;
int need = 0;
f(i, 0, n) {
if (b[i] > a[i]) {
need += (M + b[i] - 1) / b[i];
}
else {
if ((M + a[i] - 1) / a[i] <= m) {
need += (M + a[i] - 1) / a[i];
}
else {
need += m + (M - a[i] * m + b[i] - 1) / b[i];
}
}
}
if (need > m * n) R = M;
else L = M;
}
cout << (ll)L << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
348 KB |
Output is correct |
11 |
Correct |
220 ms |
4952 KB |
Output is correct |
12 |
Correct |
220 ms |
5144 KB |
Output is correct |
13 |
Correct |
133 ms |
4952 KB |
Output is correct |
14 |
Correct |
264 ms |
5140 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
331 ms |
4956 KB |
Output is correct |
17 |
Correct |
236 ms |
5148 KB |
Output is correct |
18 |
Correct |
205 ms |
5140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
331 ms |
4956 KB |
Output is correct |
3 |
Correct |
236 ms |
5148 KB |
Output is correct |
4 |
Correct |
205 ms |
5140 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
104 ms |
2792 KB |
Output is correct |
14 |
Correct |
70 ms |
2012 KB |
Output is correct |
15 |
Correct |
51 ms |
1628 KB |
Output is correct |
16 |
Correct |
45 ms |
1396 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
6 ms |
552 KB |
Output is correct |
23 |
Correct |
5 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
348 KB |
Output is correct |
11 |
Correct |
220 ms |
4952 KB |
Output is correct |
12 |
Correct |
220 ms |
5144 KB |
Output is correct |
13 |
Correct |
133 ms |
4952 KB |
Output is correct |
14 |
Correct |
264 ms |
5140 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
104 ms |
2792 KB |
Output is correct |
24 |
Correct |
70 ms |
2012 KB |
Output is correct |
25 |
Correct |
51 ms |
1628 KB |
Output is correct |
26 |
Correct |
45 ms |
1396 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
6 ms |
552 KB |
Output is correct |
33 |
Correct |
5 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
331 ms |
4956 KB |
Output is correct |
36 |
Correct |
236 ms |
5148 KB |
Output is correct |
37 |
Correct |
205 ms |
5140 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
600 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
360 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
4 ms |
604 KB |
Output is correct |
46 |
Correct |
8 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
43 ms |
2268 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
4 ms |
604 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
112 ms |
5468 KB |
Output is correct |
56 |
Correct |
50 ms |
3304 KB |
Output is correct |
57 |
Correct |
90 ms |
3288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
104 ms |
2792 KB |
Output is correct |
10 |
Correct |
70 ms |
2012 KB |
Output is correct |
11 |
Correct |
51 ms |
1628 KB |
Output is correct |
12 |
Correct |
45 ms |
1396 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
6 ms |
552 KB |
Output is correct |
19 |
Correct |
5 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
331 ms |
4956 KB |
Output is correct |
22 |
Correct |
236 ms |
5148 KB |
Output is correct |
23 |
Correct |
205 ms |
5140 KB |
Output is correct |
24 |
Correct |
34 ms |
1884 KB |
Output is correct |
25 |
Correct |
100 ms |
5152 KB |
Output is correct |
26 |
Correct |
27 ms |
1372 KB |
Output is correct |
27 |
Correct |
218 ms |
10776 KB |
Output is correct |
28 |
Correct |
216 ms |
10780 KB |
Output is correct |
29 |
Correct |
218 ms |
10832 KB |
Output is correct |
30 |
Correct |
219 ms |
10952 KB |
Output is correct |
31 |
Correct |
207 ms |
10836 KB |
Output is correct |
32 |
Correct |
324 ms |
6312 KB |
Output is correct |
33 |
Incorrect |
210 ms |
11408 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
348 KB |
Output is correct |
11 |
Correct |
220 ms |
4952 KB |
Output is correct |
12 |
Correct |
220 ms |
5144 KB |
Output is correct |
13 |
Correct |
133 ms |
4952 KB |
Output is correct |
14 |
Correct |
264 ms |
5140 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
104 ms |
2792 KB |
Output is correct |
24 |
Correct |
70 ms |
2012 KB |
Output is correct |
25 |
Correct |
51 ms |
1628 KB |
Output is correct |
26 |
Correct |
45 ms |
1396 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
6 ms |
552 KB |
Output is correct |
33 |
Correct |
5 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
600 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
360 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
4 ms |
604 KB |
Output is correct |
42 |
Correct |
8 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
43 ms |
2268 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
4 ms |
604 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
112 ms |
5468 KB |
Output is correct |
52 |
Correct |
50 ms |
3304 KB |
Output is correct |
53 |
Correct |
90 ms |
3288 KB |
Output is correct |
54 |
Correct |
34 ms |
1884 KB |
Output is correct |
55 |
Correct |
100 ms |
5152 KB |
Output is correct |
56 |
Correct |
27 ms |
1372 KB |
Output is correct |
57 |
Correct |
218 ms |
10776 KB |
Output is correct |
58 |
Correct |
216 ms |
10780 KB |
Output is correct |
59 |
Correct |
218 ms |
10832 KB |
Output is correct |
60 |
Correct |
219 ms |
10952 KB |
Output is correct |
61 |
Correct |
207 ms |
10836 KB |
Output is correct |
62 |
Correct |
324 ms |
6312 KB |
Output is correct |
63 |
Incorrect |
210 ms |
11408 KB |
Output isn't correct |
64 |
Halted |
0 ms |
0 KB |
- |