#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pb push_back
const int mxN = (int)3e5+10;
int n, m, a[mxN], b[mxN];
bool chk(int lim){
int tot = n*m;
for(int i = 1; i <= n; i++){
int num = min((lim+a[i]-1)/a[i], m);
int x = num*a[i]; tot-=num;
if(lim>x) tot-=((lim-x)+b[i]-1)/b[i];
if(tot<0) return 0;
}
return 1;
}
void solve(){
cin >> n >> m;
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]);
int l = 0, r = (int)1e18;
while(l<r){
int mid = (l+r+1)/2;
if(chk(mid)) l=mid;
else r=mid-1;
}
cout << l;
}
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int t = 1; //cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
288 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
92 ms |
5000 KB |
Output is correct |
12 |
Correct |
94 ms |
4900 KB |
Output is correct |
13 |
Correct |
96 ms |
5044 KB |
Output is correct |
14 |
Correct |
71 ms |
4912 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
33 ms |
6172 KB |
Output is correct |
17 |
Correct |
121 ms |
11440 KB |
Output is correct |
18 |
Correct |
101 ms |
10884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
33 ms |
6172 KB |
Output is correct |
3 |
Correct |
121 ms |
11440 KB |
Output is correct |
4 |
Correct |
101 ms |
10884 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 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 |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
52 ms |
2664 KB |
Output is correct |
14 |
Correct |
35 ms |
1876 KB |
Output is correct |
15 |
Correct |
27 ms |
1400 KB |
Output is correct |
16 |
Correct |
27 ms |
1196 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
288 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
92 ms |
5000 KB |
Output is correct |
12 |
Correct |
94 ms |
4900 KB |
Output is correct |
13 |
Correct |
96 ms |
5044 KB |
Output is correct |
14 |
Correct |
71 ms |
4912 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 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 |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
52 ms |
2664 KB |
Output is correct |
24 |
Correct |
35 ms |
1876 KB |
Output is correct |
25 |
Correct |
27 ms |
1400 KB |
Output is correct |
26 |
Correct |
27 ms |
1196 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
444 KB |
Output is correct |
34 |
Correct |
1 ms |
328 KB |
Output is correct |
35 |
Correct |
33 ms |
6172 KB |
Output is correct |
36 |
Correct |
121 ms |
11440 KB |
Output is correct |
37 |
Correct |
101 ms |
10884 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
328 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
3 ms |
468 KB |
Output is correct |
46 |
Correct |
5 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
20 ms |
2096 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
324 KB |
Output is correct |
51 |
Correct |
4 ms |
464 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
57 ms |
5512 KB |
Output is correct |
56 |
Correct |
39 ms |
3168 KB |
Output is correct |
57 |
Correct |
34 ms |
3092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 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 |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
52 ms |
2664 KB |
Output is correct |
10 |
Correct |
35 ms |
1876 KB |
Output is correct |
11 |
Correct |
27 ms |
1400 KB |
Output is correct |
12 |
Correct |
27 ms |
1196 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
444 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
33 ms |
6172 KB |
Output is correct |
22 |
Correct |
121 ms |
11440 KB |
Output is correct |
23 |
Correct |
101 ms |
10884 KB |
Output is correct |
24 |
Correct |
33 ms |
1824 KB |
Output is correct |
25 |
Correct |
78 ms |
4904 KB |
Output is correct |
26 |
Correct |
14 ms |
1428 KB |
Output is correct |
27 |
Correct |
98 ms |
10792 KB |
Output is correct |
28 |
Correct |
110 ms |
10744 KB |
Output is correct |
29 |
Correct |
123 ms |
10716 KB |
Output is correct |
30 |
Correct |
147 ms |
10864 KB |
Output is correct |
31 |
Correct |
209 ms |
10716 KB |
Output is correct |
32 |
Correct |
149 ms |
6096 KB |
Output is correct |
33 |
Correct |
250 ms |
11452 KB |
Output is correct |
34 |
Correct |
167 ms |
6172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
288 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
92 ms |
5000 KB |
Output is correct |
12 |
Correct |
94 ms |
4900 KB |
Output is correct |
13 |
Correct |
96 ms |
5044 KB |
Output is correct |
14 |
Correct |
71 ms |
4912 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 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 |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
52 ms |
2664 KB |
Output is correct |
24 |
Correct |
35 ms |
1876 KB |
Output is correct |
25 |
Correct |
27 ms |
1400 KB |
Output is correct |
26 |
Correct |
27 ms |
1196 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
444 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
328 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
3 ms |
468 KB |
Output is correct |
42 |
Correct |
5 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
20 ms |
2096 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
324 KB |
Output is correct |
47 |
Correct |
4 ms |
464 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
57 ms |
5512 KB |
Output is correct |
52 |
Correct |
39 ms |
3168 KB |
Output is correct |
53 |
Correct |
34 ms |
3092 KB |
Output is correct |
54 |
Correct |
33 ms |
1824 KB |
Output is correct |
55 |
Correct |
78 ms |
4904 KB |
Output is correct |
56 |
Correct |
14 ms |
1428 KB |
Output is correct |
57 |
Correct |
98 ms |
10792 KB |
Output is correct |
58 |
Correct |
110 ms |
10744 KB |
Output is correct |
59 |
Correct |
123 ms |
10716 KB |
Output is correct |
60 |
Correct |
147 ms |
10864 KB |
Output is correct |
61 |
Correct |
209 ms |
10716 KB |
Output is correct |
62 |
Correct |
149 ms |
6096 KB |
Output is correct |
63 |
Correct |
250 ms |
11452 KB |
Output is correct |
64 |
Correct |
167 ms |
6172 KB |
Output is correct |
65 |
Correct |
1 ms |
328 KB |
Output is correct |
66 |
Correct |
33 ms |
6172 KB |
Output is correct |
67 |
Correct |
121 ms |
11440 KB |
Output is correct |
68 |
Correct |
101 ms |
10884 KB |
Output is correct |
69 |
Correct |
25 ms |
1452 KB |
Output is correct |
70 |
Correct |
8 ms |
612 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
36 ms |
1748 KB |
Output is correct |
73 |
Correct |
8 ms |
684 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
136 ms |
10744 KB |
Output is correct |
76 |
Correct |
126 ms |
10836 KB |
Output is correct |
77 |
Correct |
139 ms |
10796 KB |
Output is correct |
78 |
Correct |
194 ms |
10796 KB |
Output is correct |
79 |
Correct |
243 ms |
10700 KB |
Output is correct |
80 |
Correct |
246 ms |
10828 KB |
Output is correct |
81 |
Correct |
226 ms |
8808 KB |
Output is correct |
82 |
Correct |
229 ms |
8824 KB |
Output is correct |