#include <bits/stdc++.h>
using ll = long long;
// #define int ll
using namespace std;
#define sz(x) (int)(x).size()
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, l, r) for(int i = l; i >= r; i--)
#define fi first
#define se second
#define mod 998244353
#define db(x) cerr << __LINE__ << " " << #x << " " << x << "\n"
using vi = vector<int>;
using pi = pair<int, int>;
const ll N = 500005;
const ll inf = 1e18;
ll n, m, a[N], b[N];
bool chk(ll x){
ll res = 0;
foru(i, 1, n){
if(a[i] > b[i]){
ll z = (x + a[i] - 1) / a[i];
z = min(z, m);
ll nw = inf;
foru(j, max(z - 2, 0ll), z){
ll rem = max(x - a[i] * j, 0ll);
nw = min(nw, j + (rem + b[i] - 1) / b[i]);
}
res += nw;
}
else{
res += (x + b[i] - 1) / b[i];
}
if(res > m * n) return false;
}
return true;
}
void solve(){
cin >> n >> m;
foru(i, 1, n) cin >> a[i];
foru(i, 1, n) cin >> b[i];
ll l = 0, r = inf;
while(l != r){
ll mid = (l + r + 1) >> 1;
if(chk(mid)) l = mid;
else r = mid - 1;
}
cout << l << "\n";
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
153 ms |
10724 KB |
Output is correct |
12 |
Correct |
137 ms |
10700 KB |
Output is correct |
13 |
Correct |
86 ms |
8800 KB |
Output is correct |
14 |
Correct |
145 ms |
8824 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
30 ms |
6180 KB |
Output is correct |
17 |
Correct |
107 ms |
11372 KB |
Output is correct |
18 |
Correct |
97 ms |
10708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
30 ms |
6180 KB |
Output is correct |
3 |
Correct |
107 ms |
11372 KB |
Output is correct |
4 |
Correct |
97 ms |
10708 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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
49 ms |
5456 KB |
Output is correct |
14 |
Correct |
33 ms |
3788 KB |
Output is correct |
15 |
Correct |
24 ms |
2896 KB |
Output is correct |
16 |
Correct |
21 ms |
2360 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
153 ms |
10724 KB |
Output is correct |
12 |
Correct |
137 ms |
10700 KB |
Output is correct |
13 |
Correct |
86 ms |
8800 KB |
Output is correct |
14 |
Correct |
145 ms |
8824 KB |
Output is correct |
15 |
Correct |
0 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 |
1 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 |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
49 ms |
5456 KB |
Output is correct |
24 |
Correct |
33 ms |
3788 KB |
Output is correct |
25 |
Correct |
24 ms |
2896 KB |
Output is correct |
26 |
Correct |
21 ms |
2360 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
328 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
30 ms |
6180 KB |
Output is correct |
36 |
Correct |
107 ms |
11372 KB |
Output is correct |
37 |
Correct |
97 ms |
10708 KB |
Output is correct |
38 |
Correct |
1 ms |
328 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
5 ms |
516 KB |
Output is correct |
46 |
Correct |
5 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
29 ms |
2048 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
4 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
89 ms |
5452 KB |
Output is correct |
56 |
Correct |
33 ms |
3136 KB |
Output is correct |
57 |
Correct |
69 ms |
3160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
49 ms |
5456 KB |
Output is correct |
10 |
Correct |
33 ms |
3788 KB |
Output is correct |
11 |
Correct |
24 ms |
2896 KB |
Output is correct |
12 |
Correct |
21 ms |
2360 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
30 ms |
6180 KB |
Output is correct |
22 |
Correct |
107 ms |
11372 KB |
Output is correct |
23 |
Correct |
97 ms |
10708 KB |
Output is correct |
24 |
Correct |
29 ms |
1944 KB |
Output is correct |
25 |
Correct |
74 ms |
5232 KB |
Output is correct |
26 |
Correct |
13 ms |
1364 KB |
Output is correct |
27 |
Correct |
104 ms |
10820 KB |
Output is correct |
28 |
Correct |
97 ms |
10716 KB |
Output is correct |
29 |
Correct |
101 ms |
10708 KB |
Output is correct |
30 |
Correct |
126 ms |
10824 KB |
Output is correct |
31 |
Correct |
206 ms |
10700 KB |
Output is correct |
32 |
Correct |
116 ms |
6188 KB |
Output is correct |
33 |
Correct |
247 ms |
11460 KB |
Output is correct |
34 |
Correct |
113 ms |
6180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
153 ms |
10724 KB |
Output is correct |
12 |
Correct |
137 ms |
10700 KB |
Output is correct |
13 |
Correct |
86 ms |
8800 KB |
Output is correct |
14 |
Correct |
145 ms |
8824 KB |
Output is correct |
15 |
Correct |
0 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 |
1 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 |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
49 ms |
5456 KB |
Output is correct |
24 |
Correct |
33 ms |
3788 KB |
Output is correct |
25 |
Correct |
24 ms |
2896 KB |
Output is correct |
26 |
Correct |
21 ms |
2360 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
328 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
328 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
5 ms |
516 KB |
Output is correct |
42 |
Correct |
5 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
29 ms |
2048 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
4 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
89 ms |
5452 KB |
Output is correct |
52 |
Correct |
33 ms |
3136 KB |
Output is correct |
53 |
Correct |
69 ms |
3160 KB |
Output is correct |
54 |
Correct |
29 ms |
1944 KB |
Output is correct |
55 |
Correct |
74 ms |
5232 KB |
Output is correct |
56 |
Correct |
13 ms |
1364 KB |
Output is correct |
57 |
Correct |
104 ms |
10820 KB |
Output is correct |
58 |
Correct |
97 ms |
10716 KB |
Output is correct |
59 |
Correct |
101 ms |
10708 KB |
Output is correct |
60 |
Correct |
126 ms |
10824 KB |
Output is correct |
61 |
Correct |
206 ms |
10700 KB |
Output is correct |
62 |
Correct |
116 ms |
6188 KB |
Output is correct |
63 |
Correct |
247 ms |
11460 KB |
Output is correct |
64 |
Correct |
113 ms |
6180 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
30 ms |
6180 KB |
Output is correct |
67 |
Correct |
107 ms |
11372 KB |
Output is correct |
68 |
Correct |
97 ms |
10708 KB |
Output is correct |
69 |
Correct |
37 ms |
1364 KB |
Output is correct |
70 |
Correct |
10 ms |
612 KB |
Output is correct |
71 |
Correct |
1 ms |
328 KB |
Output is correct |
72 |
Correct |
51 ms |
1832 KB |
Output is correct |
73 |
Correct |
11 ms |
596 KB |
Output is correct |
74 |
Correct |
1 ms |
344 KB |
Output is correct |
75 |
Correct |
176 ms |
10852 KB |
Output is correct |
76 |
Correct |
215 ms |
10808 KB |
Output is correct |
77 |
Correct |
202 ms |
10700 KB |
Output is correct |
78 |
Correct |
263 ms |
10828 KB |
Output is correct |
79 |
Correct |
340 ms |
10692 KB |
Output is correct |
80 |
Correct |
368 ms |
10908 KB |
Output is correct |
81 |
Correct |
222 ms |
8916 KB |
Output is correct |
82 |
Correct |
655 ms |
8824 KB |
Output is correct |