#include <bits/stdc++.h>
#define x first
#define y second
#define sz(a) (int)a.size()
#define pb push_back
#define int long long
using namespace std;
typedef long long ll;
void solve();
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
int a[300010], b[300010];
int n, m;
int check(int x) {
int cnt = m * n;
for (int i = 0; i < n; ++i) {
if (a[i] > b[i]) {
int f = (x + a[i] - 1) / a[i];
if (f <= m)
cnt -= f;
else {
cnt -= m;
cnt -= (x - a[i] * m + b[i] - 1) / b[i];
}
} else {
cnt -= (x + b[i] - 1) / b[i];
}
if (cnt < 0)
return false;
}
return true;
}
void solve() {
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i)
cin >> b[i];
int l = 0, r = 2e18;
l = 0, r = 1e18;
while (r - l > 1) {
int mid = (r + l) / 2;
if (check(mid))
l = mid;
else
r = mid;
}
cout << l << endl;
}
//923953850098595069
//890909762780980010
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
101 ms |
5224 KB |
Output is correct |
12 |
Correct |
133 ms |
5252 KB |
Output is correct |
13 |
Correct |
92 ms |
5132 KB |
Output is correct |
14 |
Correct |
74 ms |
5140 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
32 ms |
5212 KB |
Output is correct |
17 |
Correct |
103 ms |
5224 KB |
Output is correct |
18 |
Correct |
129 ms |
5156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
32 ms |
5212 KB |
Output is correct |
3 |
Correct |
103 ms |
5224 KB |
Output is correct |
4 |
Correct |
129 ms |
5156 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
52 ms |
2864 KB |
Output is correct |
14 |
Correct |
44 ms |
2108 KB |
Output is correct |
15 |
Correct |
27 ms |
1736 KB |
Output is correct |
16 |
Correct |
23 ms |
1484 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
101 ms |
5224 KB |
Output is correct |
12 |
Correct |
133 ms |
5252 KB |
Output is correct |
13 |
Correct |
92 ms |
5132 KB |
Output is correct |
14 |
Correct |
74 ms |
5140 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
52 ms |
2864 KB |
Output is correct |
24 |
Correct |
44 ms |
2108 KB |
Output is correct |
25 |
Correct |
27 ms |
1736 KB |
Output is correct |
26 |
Correct |
23 ms |
1484 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
3 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
32 ms |
5212 KB |
Output is correct |
36 |
Correct |
103 ms |
5224 KB |
Output is correct |
37 |
Correct |
129 ms |
5156 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
1 ms |
204 KB |
Output is correct |
45 |
Correct |
3 ms |
460 KB |
Output is correct |
46 |
Correct |
4 ms |
584 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
21 ms |
1364 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
3 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
204 KB |
Output is correct |
53 |
Correct |
1 ms |
204 KB |
Output is correct |
54 |
Correct |
1 ms |
204 KB |
Output is correct |
55 |
Correct |
59 ms |
2884 KB |
Output is correct |
56 |
Correct |
34 ms |
2124 KB |
Output is correct |
57 |
Correct |
27 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
52 ms |
2864 KB |
Output is correct |
10 |
Correct |
44 ms |
2108 KB |
Output is correct |
11 |
Correct |
27 ms |
1736 KB |
Output is correct |
12 |
Correct |
23 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
32 ms |
5212 KB |
Output is correct |
22 |
Correct |
103 ms |
5224 KB |
Output is correct |
23 |
Correct |
129 ms |
5156 KB |
Output is correct |
24 |
Correct |
29 ms |
1300 KB |
Output is correct |
25 |
Correct |
75 ms |
2740 KB |
Output is correct |
26 |
Correct |
16 ms |
972 KB |
Output is correct |
27 |
Correct |
117 ms |
5352 KB |
Output is correct |
28 |
Correct |
103 ms |
5164 KB |
Output is correct |
29 |
Correct |
101 ms |
5252 KB |
Output is correct |
30 |
Correct |
160 ms |
5248 KB |
Output is correct |
31 |
Correct |
226 ms |
5208 KB |
Output is correct |
32 |
Correct |
116 ms |
5248 KB |
Output is correct |
33 |
Incorrect |
250 ms |
5248 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
101 ms |
5224 KB |
Output is correct |
12 |
Correct |
133 ms |
5252 KB |
Output is correct |
13 |
Correct |
92 ms |
5132 KB |
Output is correct |
14 |
Correct |
74 ms |
5140 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
52 ms |
2864 KB |
Output is correct |
24 |
Correct |
44 ms |
2108 KB |
Output is correct |
25 |
Correct |
27 ms |
1736 KB |
Output is correct |
26 |
Correct |
23 ms |
1484 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
3 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
3 ms |
460 KB |
Output is correct |
42 |
Correct |
4 ms |
584 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
21 ms |
1364 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
3 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
1 ms |
204 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
59 ms |
2884 KB |
Output is correct |
52 |
Correct |
34 ms |
2124 KB |
Output is correct |
53 |
Correct |
27 ms |
2040 KB |
Output is correct |
54 |
Correct |
29 ms |
1300 KB |
Output is correct |
55 |
Correct |
75 ms |
2740 KB |
Output is correct |
56 |
Correct |
16 ms |
972 KB |
Output is correct |
57 |
Correct |
117 ms |
5352 KB |
Output is correct |
58 |
Correct |
103 ms |
5164 KB |
Output is correct |
59 |
Correct |
101 ms |
5252 KB |
Output is correct |
60 |
Correct |
160 ms |
5248 KB |
Output is correct |
61 |
Correct |
226 ms |
5208 KB |
Output is correct |
62 |
Correct |
116 ms |
5248 KB |
Output is correct |
63 |
Incorrect |
250 ms |
5248 KB |
Output isn't correct |
64 |
Halted |
0 ms |
0 KB |
- |