#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 << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int t = 1; //cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
93 ms |
4940 KB |
Output is correct |
12 |
Correct |
96 ms |
4908 KB |
Output is correct |
13 |
Correct |
94 ms |
5000 KB |
Output is correct |
14 |
Correct |
73 ms |
5120 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
35 ms |
4940 KB |
Output is correct |
17 |
Correct |
115 ms |
5056 KB |
Output is correct |
18 |
Correct |
92 ms |
4896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
35 ms |
4940 KB |
Output is correct |
3 |
Correct |
115 ms |
5056 KB |
Output is correct |
4 |
Correct |
92 ms |
4896 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
54 ms |
2660 KB |
Output is correct |
14 |
Correct |
36 ms |
1892 KB |
Output is correct |
15 |
Correct |
24 ms |
1468 KB |
Output is correct |
16 |
Correct |
22 ms |
1236 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 |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
93 ms |
4940 KB |
Output is correct |
12 |
Correct |
96 ms |
4908 KB |
Output is correct |
13 |
Correct |
94 ms |
5000 KB |
Output is correct |
14 |
Correct |
73 ms |
5120 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 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 |
212 KB |
Output is correct |
23 |
Correct |
54 ms |
2660 KB |
Output is correct |
24 |
Correct |
36 ms |
1892 KB |
Output is correct |
25 |
Correct |
24 ms |
1468 KB |
Output is correct |
26 |
Correct |
22 ms |
1236 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 |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
35 ms |
4940 KB |
Output is correct |
36 |
Correct |
115 ms |
5056 KB |
Output is correct |
37 |
Correct |
92 ms |
4896 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
328 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
332 KB |
Output is correct |
45 |
Correct |
3 ms |
468 KB |
Output is correct |
46 |
Correct |
4 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
22 ms |
2132 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
3 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
59 ms |
5420 KB |
Output is correct |
56 |
Correct |
39 ms |
3148 KB |
Output is correct |
57 |
Correct |
28 ms |
3116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
54 ms |
2660 KB |
Output is correct |
10 |
Correct |
36 ms |
1892 KB |
Output is correct |
11 |
Correct |
24 ms |
1468 KB |
Output is correct |
12 |
Correct |
22 ms |
1236 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 |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
35 ms |
4940 KB |
Output is correct |
22 |
Correct |
115 ms |
5056 KB |
Output is correct |
23 |
Correct |
92 ms |
4896 KB |
Output is correct |
24 |
Correct |
33 ms |
1060 KB |
Output is correct |
25 |
Correct |
76 ms |
2416 KB |
Output is correct |
26 |
Correct |
14 ms |
724 KB |
Output is correct |
27 |
Correct |
94 ms |
5004 KB |
Output is correct |
28 |
Correct |
108 ms |
4940 KB |
Output is correct |
29 |
Correct |
106 ms |
5000 KB |
Output is correct |
30 |
Correct |
133 ms |
4940 KB |
Output is correct |
31 |
Correct |
205 ms |
4972 KB |
Output is correct |
32 |
Correct |
153 ms |
4996 KB |
Output is correct |
33 |
Correct |
242 ms |
11460 KB |
Output is correct |
34 |
Correct |
166 ms |
6128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
93 ms |
4940 KB |
Output is correct |
12 |
Correct |
96 ms |
4908 KB |
Output is correct |
13 |
Correct |
94 ms |
5000 KB |
Output is correct |
14 |
Correct |
73 ms |
5120 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 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 |
212 KB |
Output is correct |
23 |
Correct |
54 ms |
2660 KB |
Output is correct |
24 |
Correct |
36 ms |
1892 KB |
Output is correct |
25 |
Correct |
24 ms |
1468 KB |
Output is correct |
26 |
Correct |
22 ms |
1236 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 |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
328 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
41 |
Correct |
3 ms |
468 KB |
Output is correct |
42 |
Correct |
4 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
22 ms |
2132 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
3 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
59 ms |
5420 KB |
Output is correct |
52 |
Correct |
39 ms |
3148 KB |
Output is correct |
53 |
Correct |
28 ms |
3116 KB |
Output is correct |
54 |
Correct |
33 ms |
1060 KB |
Output is correct |
55 |
Correct |
76 ms |
2416 KB |
Output is correct |
56 |
Correct |
14 ms |
724 KB |
Output is correct |
57 |
Correct |
94 ms |
5004 KB |
Output is correct |
58 |
Correct |
108 ms |
4940 KB |
Output is correct |
59 |
Correct |
106 ms |
5000 KB |
Output is correct |
60 |
Correct |
133 ms |
4940 KB |
Output is correct |
61 |
Correct |
205 ms |
4972 KB |
Output is correct |
62 |
Correct |
153 ms |
4996 KB |
Output is correct |
63 |
Correct |
242 ms |
11460 KB |
Output is correct |
64 |
Correct |
166 ms |
6128 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
35 ms |
4940 KB |
Output is correct |
67 |
Correct |
115 ms |
5056 KB |
Output is correct |
68 |
Correct |
92 ms |
4896 KB |
Output is correct |
69 |
Correct |
26 ms |
1364 KB |
Output is correct |
70 |
Correct |
7 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 |
596 KB |
Output is correct |
74 |
Correct |
1 ms |
336 KB |
Output is correct |
75 |
Correct |
118 ms |
10744 KB |
Output is correct |
76 |
Correct |
126 ms |
10896 KB |
Output is correct |
77 |
Correct |
144 ms |
10700 KB |
Output is correct |
78 |
Correct |
179 ms |
10808 KB |
Output is correct |
79 |
Correct |
240 ms |
10796 KB |
Output is correct |
80 |
Correct |
246 ms |
10808 KB |
Output is correct |
81 |
Correct |
227 ms |
8876 KB |
Output is correct |
82 |
Correct |
225 ms |
8936 KB |
Output is correct |