#include<bits/stdc++.h>
#define int long long
#define ms(v) memset(v, -1, sizeof v)
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define srt(v) sort(v.begin(), v.end())
#define INF 1e15
#define N 300010
using namespace std;
int n, m;
int a[N], b[N];
int32_t main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
for(int i = 1;i <= n;i++){
cin >> b[i];
}
int l = 0, r = (int) 2e18;
while(l < r){
int mid = (l+r) >> 1;
int res = 0;
// cout << l << " " << r << "\n";
for(int i = 1;i <= n;i++){
int aux = mid;
if(a[i] > b[i]){
if(a[i]*m < aux){
aux -= a[i]*m;
res += m;
}
else{
int t = (aux + a[i] - 1)/a[i];
res += t;
if(res > n*m){r = mid; break;}
continue;
}
}
int t = (aux + b[i] - 1)/b[i];
res += t;
if(res > n*m){r = mid; break;}
}
if(res <= n*m){
l = mid+1;
}
}
l--;
cout << l << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
340 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 |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
432 KB |
Output is correct |
11 |
Correct |
112 ms |
9200 KB |
Output is correct |
12 |
Correct |
130 ms |
9196 KB |
Output is correct |
13 |
Correct |
90 ms |
8812 KB |
Output is correct |
14 |
Correct |
81 ms |
8696 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
38 ms |
6088 KB |
Output is correct |
17 |
Correct |
119 ms |
9348 KB |
Output is correct |
18 |
Correct |
118 ms |
9360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
38 ms |
6088 KB |
Output is correct |
3 |
Correct |
119 ms |
9348 KB |
Output is correct |
4 |
Correct |
118 ms |
9360 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 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 |
328 KB |
Output is correct |
13 |
Correct |
53 ms |
5528 KB |
Output is correct |
14 |
Correct |
38 ms |
3788 KB |
Output is correct |
15 |
Correct |
26 ms |
2892 KB |
Output is correct |
16 |
Correct |
21 ms |
2432 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
0 ms |
328 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
392 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
340 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 |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
432 KB |
Output is correct |
11 |
Correct |
112 ms |
9200 KB |
Output is correct |
12 |
Correct |
130 ms |
9196 KB |
Output is correct |
13 |
Correct |
90 ms |
8812 KB |
Output is correct |
14 |
Correct |
81 ms |
8696 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 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 |
328 KB |
Output is correct |
23 |
Correct |
53 ms |
5528 KB |
Output is correct |
24 |
Correct |
38 ms |
3788 KB |
Output is correct |
25 |
Correct |
26 ms |
2892 KB |
Output is correct |
26 |
Correct |
21 ms |
2432 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
324 KB |
Output is correct |
29 |
Correct |
0 ms |
328 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
392 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
38 ms |
6088 KB |
Output is correct |
36 |
Correct |
119 ms |
9348 KB |
Output is correct |
37 |
Correct |
118 ms |
9360 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
3 ms |
440 KB |
Output is correct |
46 |
Correct |
4 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
20 ms |
2020 KB |
Output is correct |
49 |
Correct |
1 ms |
324 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
2 ms |
468 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
324 KB |
Output is correct |
55 |
Correct |
57 ms |
5384 KB |
Output is correct |
56 |
Correct |
33 ms |
3156 KB |
Output is correct |
57 |
Correct |
28 ms |
3080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 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 |
328 KB |
Output is correct |
9 |
Correct |
53 ms |
5528 KB |
Output is correct |
10 |
Correct |
38 ms |
3788 KB |
Output is correct |
11 |
Correct |
26 ms |
2892 KB |
Output is correct |
12 |
Correct |
21 ms |
2432 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
0 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
392 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
38 ms |
6088 KB |
Output is correct |
22 |
Correct |
119 ms |
9348 KB |
Output is correct |
23 |
Correct |
118 ms |
9360 KB |
Output is correct |
24 |
Correct |
35 ms |
1936 KB |
Output is correct |
25 |
Correct |
86 ms |
4908 KB |
Output is correct |
26 |
Correct |
15 ms |
1424 KB |
Output is correct |
27 |
Correct |
101 ms |
10792 KB |
Output is correct |
28 |
Correct |
107 ms |
10792 KB |
Output is correct |
29 |
Correct |
114 ms |
10700 KB |
Output is correct |
30 |
Correct |
137 ms |
10680 KB |
Output is correct |
31 |
Correct |
204 ms |
10792 KB |
Output is correct |
32 |
Correct |
130 ms |
6092 KB |
Output is correct |
33 |
Correct |
251 ms |
11456 KB |
Output is correct |
34 |
Correct |
125 ms |
6104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
340 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 |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
432 KB |
Output is correct |
11 |
Correct |
112 ms |
9200 KB |
Output is correct |
12 |
Correct |
130 ms |
9196 KB |
Output is correct |
13 |
Correct |
90 ms |
8812 KB |
Output is correct |
14 |
Correct |
81 ms |
8696 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 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 |
328 KB |
Output is correct |
23 |
Correct |
53 ms |
5528 KB |
Output is correct |
24 |
Correct |
38 ms |
3788 KB |
Output is correct |
25 |
Correct |
26 ms |
2892 KB |
Output is correct |
26 |
Correct |
21 ms |
2432 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
324 KB |
Output is correct |
29 |
Correct |
0 ms |
328 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
392 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
3 ms |
440 KB |
Output is correct |
42 |
Correct |
4 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
20 ms |
2020 KB |
Output is correct |
45 |
Correct |
1 ms |
324 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
2 ms |
468 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
324 KB |
Output is correct |
51 |
Correct |
57 ms |
5384 KB |
Output is correct |
52 |
Correct |
33 ms |
3156 KB |
Output is correct |
53 |
Correct |
28 ms |
3080 KB |
Output is correct |
54 |
Correct |
35 ms |
1936 KB |
Output is correct |
55 |
Correct |
86 ms |
4908 KB |
Output is correct |
56 |
Correct |
15 ms |
1424 KB |
Output is correct |
57 |
Correct |
101 ms |
10792 KB |
Output is correct |
58 |
Correct |
107 ms |
10792 KB |
Output is correct |
59 |
Correct |
114 ms |
10700 KB |
Output is correct |
60 |
Correct |
137 ms |
10680 KB |
Output is correct |
61 |
Correct |
204 ms |
10792 KB |
Output is correct |
62 |
Correct |
130 ms |
6092 KB |
Output is correct |
63 |
Correct |
251 ms |
11456 KB |
Output is correct |
64 |
Correct |
125 ms |
6104 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
38 ms |
6088 KB |
Output is correct |
67 |
Correct |
119 ms |
9348 KB |
Output is correct |
68 |
Correct |
118 ms |
9360 KB |
Output is correct |
69 |
Correct |
21 ms |
1384 KB |
Output is correct |
70 |
Correct |
6 ms |
596 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
33 ms |
1760 KB |
Output is correct |
73 |
Correct |
8 ms |
724 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
124 ms |
10804 KB |
Output is correct |
76 |
Correct |
133 ms |
10712 KB |
Output is correct |
77 |
Correct |
133 ms |
10776 KB |
Output is correct |
78 |
Correct |
162 ms |
10712 KB |
Output is correct |
79 |
Correct |
213 ms |
10704 KB |
Output is correct |
80 |
Correct |
226 ms |
10816 KB |
Output is correct |
81 |
Correct |
232 ms |
8852 KB |
Output is correct |
82 |
Correct |
125 ms |
8820 KB |
Output is correct |