#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN = 3e5+5, M = 1e9+7;
ll n, m, a[mxN], b[mxN];
bool f(ll val){
ll ret = 0;
for(int i = 0; i<n; ++i){
if(a[i] <= b[i]){
ret += (val+b[i]-1)/b[i];
}
else{
ll flag = (val+a[i]-1)/a[i];
ll upd = 1e18;
for(ll j = max(flag-2, 0ll); j<=flag; ++j){
ll rem = max(0ll, val - a[i]*j);
upd = min(upd, j + (rem+b[i]-1)/b[i]);
}
ret += upd;
}
if(ret > n*m) return 0;
}
return 1;
}
int main(){
#ifdef _DEBUG
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
cin >> n >> m;
for(int i = 0; i<n; ++i){
cin >> a[i];
}
for(int i = 0; i<n; ++i){
cin >> b[i];
}
ll l = 0, r = 1e18;
while(l != r){
ll m = (l+r+1)/2;
if(f(m)){
l = m;
}else{
r = m-1;
}
}
cout << l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
143 ms |
5016 KB |
Output is correct |
12 |
Correct |
191 ms |
4992 KB |
Output is correct |
13 |
Correct |
81 ms |
4980 KB |
Output is correct |
14 |
Correct |
200 ms |
4988 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
39 ms |
5100 KB |
Output is correct |
17 |
Correct |
106 ms |
4960 KB |
Output is correct |
18 |
Correct |
93 ms |
4996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
39 ms |
5100 KB |
Output is correct |
3 |
Correct |
106 ms |
4960 KB |
Output is correct |
4 |
Correct |
93 ms |
4996 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 |
1 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 |
48 ms |
2576 KB |
Output is correct |
14 |
Correct |
38 ms |
1852 KB |
Output is correct |
15 |
Correct |
23 ms |
1484 KB |
Output is correct |
16 |
Correct |
20 ms |
1252 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 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 |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
143 ms |
5016 KB |
Output is correct |
12 |
Correct |
191 ms |
4992 KB |
Output is correct |
13 |
Correct |
81 ms |
4980 KB |
Output is correct |
14 |
Correct |
200 ms |
4988 KB |
Output is correct |
15 |
Correct |
0 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 |
0 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 |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
48 ms |
2576 KB |
Output is correct |
24 |
Correct |
38 ms |
1852 KB |
Output is correct |
25 |
Correct |
23 ms |
1484 KB |
Output is correct |
26 |
Correct |
20 ms |
1252 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
3 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
39 ms |
5100 KB |
Output is correct |
36 |
Correct |
106 ms |
4960 KB |
Output is correct |
37 |
Correct |
93 ms |
4996 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 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 |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
48 ms |
2576 KB |
Output is correct |
10 |
Correct |
38 ms |
1852 KB |
Output is correct |
11 |
Correct |
23 ms |
1484 KB |
Output is correct |
12 |
Correct |
20 ms |
1252 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 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 |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
39 ms |
5100 KB |
Output is correct |
22 |
Correct |
106 ms |
4960 KB |
Output is correct |
23 |
Correct |
93 ms |
4996 KB |
Output is correct |
24 |
Correct |
29 ms |
936 KB |
Output is correct |
25 |
Correct |
68 ms |
2380 KB |
Output is correct |
26 |
Correct |
16 ms |
824 KB |
Output is correct |
27 |
Correct |
90 ms |
4936 KB |
Output is correct |
28 |
Correct |
94 ms |
4976 KB |
Output is correct |
29 |
Correct |
98 ms |
4940 KB |
Output is correct |
30 |
Correct |
120 ms |
4976 KB |
Output is correct |
31 |
Correct |
206 ms |
4872 KB |
Output is correct |
32 |
Correct |
113 ms |
4928 KB |
Output is correct |
33 |
Correct |
239 ms |
4932 KB |
Output is correct |
34 |
Correct |
114 ms |
4920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
143 ms |
5016 KB |
Output is correct |
12 |
Correct |
191 ms |
4992 KB |
Output is correct |
13 |
Correct |
81 ms |
4980 KB |
Output is correct |
14 |
Correct |
200 ms |
4988 KB |
Output is correct |
15 |
Correct |
0 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 |
0 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 |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
48 ms |
2576 KB |
Output is correct |
24 |
Correct |
38 ms |
1852 KB |
Output is correct |
25 |
Correct |
23 ms |
1484 KB |
Output is correct |
26 |
Correct |
20 ms |
1252 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
3 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |