#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m;
vector<ll> a, b;
bool F(ll x){
ll r = 0;
for(int i = 0; i < n; i++){
if(x <= a[i] * m) r += (x + a[i] - 1) / a[i];
else r += m + (x - a[i] * m + b[i] - 1) / b[i];
if(r > n * m) return 0;
}
return 1;
}
int main(){
cin >> n >> m;
a.resize(n);
b.resize(n);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) cin >> b[i];
for(int i = 0; i < n; i++) a[i] = max(a[i], b[i]);
ll lx = 0, rx = 1LL << 60;
while(rx - lx > 1){
ll mid = (rx + lx) / 2;
if(F(mid)) lx = mid;
else rx = mid;
}
cout << lx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
165 ms |
10736 KB |
Output is correct |
12 |
Correct |
166 ms |
10836 KB |
Output is correct |
13 |
Correct |
120 ms |
8704 KB |
Output is correct |
14 |
Correct |
118 ms |
8828 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
49 ms |
6292 KB |
Output is correct |
17 |
Correct |
180 ms |
11388 KB |
Output is correct |
18 |
Correct |
180 ms |
10836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
49 ms |
6292 KB |
Output is correct |
3 |
Correct |
180 ms |
11388 KB |
Output is correct |
4 |
Correct |
180 ms |
10836 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
85 ms |
5588 KB |
Output is correct |
14 |
Correct |
57 ms |
3764 KB |
Output is correct |
15 |
Correct |
45 ms |
2896 KB |
Output is correct |
16 |
Correct |
35 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
165 ms |
10736 KB |
Output is correct |
12 |
Correct |
166 ms |
10836 KB |
Output is correct |
13 |
Correct |
120 ms |
8704 KB |
Output is correct |
14 |
Correct |
118 ms |
8828 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
85 ms |
5588 KB |
Output is correct |
24 |
Correct |
57 ms |
3764 KB |
Output is correct |
25 |
Correct |
45 ms |
2896 KB |
Output is correct |
26 |
Correct |
35 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
440 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
49 ms |
6292 KB |
Output is correct |
36 |
Correct |
180 ms |
11388 KB |
Output is correct |
37 |
Correct |
180 ms |
10836 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
3 ms |
600 KB |
Output is correct |
46 |
Correct |
5 ms |
600 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
32 ms |
2244 KB |
Output is correct |
49 |
Correct |
0 ms |
600 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
5 ms |
600 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
440 KB |
Output is correct |
55 |
Correct |
86 ms |
5460 KB |
Output is correct |
56 |
Correct |
42 ms |
3268 KB |
Output is correct |
57 |
Correct |
40 ms |
3156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
85 ms |
5588 KB |
Output is correct |
10 |
Correct |
57 ms |
3764 KB |
Output is correct |
11 |
Correct |
45 ms |
2896 KB |
Output is correct |
12 |
Correct |
35 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
440 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
49 ms |
6292 KB |
Output is correct |
22 |
Correct |
180 ms |
11388 KB |
Output is correct |
23 |
Correct |
180 ms |
10836 KB |
Output is correct |
24 |
Correct |
28 ms |
1880 KB |
Output is correct |
25 |
Correct |
83 ms |
4944 KB |
Output is correct |
26 |
Correct |
20 ms |
1372 KB |
Output is correct |
27 |
Correct |
165 ms |
10752 KB |
Output is correct |
28 |
Correct |
195 ms |
11004 KB |
Output is correct |
29 |
Correct |
171 ms |
10836 KB |
Output is correct |
30 |
Correct |
178 ms |
10728 KB |
Output is correct |
31 |
Correct |
188 ms |
10880 KB |
Output is correct |
32 |
Correct |
73 ms |
6224 KB |
Output is correct |
33 |
Correct |
208 ms |
11520 KB |
Output is correct |
34 |
Correct |
70 ms |
6224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
165 ms |
10736 KB |
Output is correct |
12 |
Correct |
166 ms |
10836 KB |
Output is correct |
13 |
Correct |
120 ms |
8704 KB |
Output is correct |
14 |
Correct |
118 ms |
8828 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
85 ms |
5588 KB |
Output is correct |
24 |
Correct |
57 ms |
3764 KB |
Output is correct |
25 |
Correct |
45 ms |
2896 KB |
Output is correct |
26 |
Correct |
35 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
440 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
3 ms |
600 KB |
Output is correct |
42 |
Correct |
5 ms |
600 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
32 ms |
2244 KB |
Output is correct |
45 |
Correct |
0 ms |
600 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
5 ms |
600 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
440 KB |
Output is correct |
51 |
Correct |
86 ms |
5460 KB |
Output is correct |
52 |
Correct |
42 ms |
3268 KB |
Output is correct |
53 |
Correct |
40 ms |
3156 KB |
Output is correct |
54 |
Correct |
28 ms |
1880 KB |
Output is correct |
55 |
Correct |
83 ms |
4944 KB |
Output is correct |
56 |
Correct |
20 ms |
1372 KB |
Output is correct |
57 |
Correct |
165 ms |
10752 KB |
Output is correct |
58 |
Correct |
195 ms |
11004 KB |
Output is correct |
59 |
Correct |
171 ms |
10836 KB |
Output is correct |
60 |
Correct |
178 ms |
10728 KB |
Output is correct |
61 |
Correct |
188 ms |
10880 KB |
Output is correct |
62 |
Correct |
73 ms |
6224 KB |
Output is correct |
63 |
Correct |
208 ms |
11520 KB |
Output is correct |
64 |
Correct |
70 ms |
6224 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
49 ms |
6292 KB |
Output is correct |
67 |
Correct |
180 ms |
11388 KB |
Output is correct |
68 |
Correct |
180 ms |
10836 KB |
Output is correct |
69 |
Correct |
21 ms |
1564 KB |
Output is correct |
70 |
Correct |
9 ms |
860 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
29 ms |
1748 KB |
Output is correct |
73 |
Correct |
7 ms |
600 KB |
Output is correct |
74 |
Correct |
1 ms |
344 KB |
Output is correct |
75 |
Correct |
176 ms |
10880 KB |
Output is correct |
76 |
Correct |
183 ms |
11088 KB |
Output is correct |
77 |
Correct |
175 ms |
10832 KB |
Output is correct |
78 |
Correct |
183 ms |
10836 KB |
Output is correct |
79 |
Correct |
191 ms |
10832 KB |
Output is correct |
80 |
Correct |
194 ms |
10752 KB |
Output is correct |
81 |
Correct |
148 ms |
8788 KB |
Output is correct |
82 |
Correct |
140 ms |
8816 KB |
Output is correct |