#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
typedef long long ll;
typedef long double ld;
const ll SZ = 200'100, LG = 18, INF = 1'000'000'000'000'000'100;
ll n, m;
vector<ll> vec1, vec2;
bool check(ll val) {
vector<ll> vec;
ll left = 0;
for (int i = 0; i < n; i++) {
ll needed = (val - 1) / vec1[i] + 1;
if (needed <= m) {
left += m - needed;
vec.push_back(0);
} else {
vec.push_back(val - m * vec1[i]);
}
}
for (int i = 0; i < n; i++) {
if (vec[i] == 0) continue;
left -= (vec[i] - 1) / vec2[i] + 1;
if (left < 0) return 0;
}
return left >= 0;
}
int main() {
fastInp;
cin >> n >> m;
vec1.resize(n);
vec2.resize(n);
for (auto &c : vec1) cin >> c;
for (auto &c : vec2) cin >> c;
for (int i = 0; i < n; i++) {
vec1[i] = max(vec1[i], vec2[i]);
}
ll l = 0, r = INF;
while (r - l > 1) {
ll mid = (l + r) / 2;
if (check(mid)) {
l = mid;
} else {
r = mid;
}
}
cout << l;
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 |
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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
233 ms |
11672 KB |
Output is correct |
12 |
Correct |
236 ms |
11596 KB |
Output is correct |
13 |
Correct |
232 ms |
11648 KB |
Output is correct |
14 |
Correct |
222 ms |
11632 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
268 ms |
12768 KB |
Output is correct |
17 |
Correct |
238 ms |
18084 KB |
Output is correct |
18 |
Correct |
236 ms |
17424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
268 ms |
12768 KB |
Output is correct |
3 |
Correct |
238 ms |
18084 KB |
Output is correct |
4 |
Correct |
236 ms |
17424 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 |
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 |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
123 ms |
6052 KB |
Output is correct |
14 |
Correct |
78 ms |
3788 KB |
Output is correct |
15 |
Correct |
59 ms |
3224 KB |
Output is correct |
16 |
Correct |
43 ms |
2260 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 |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
588 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 |
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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
233 ms |
11672 KB |
Output is correct |
12 |
Correct |
236 ms |
11596 KB |
Output is correct |
13 |
Correct |
232 ms |
11648 KB |
Output is correct |
14 |
Correct |
222 ms |
11632 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 |
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 |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
123 ms |
6052 KB |
Output is correct |
24 |
Correct |
78 ms |
3788 KB |
Output is correct |
25 |
Correct |
59 ms |
3224 KB |
Output is correct |
26 |
Correct |
43 ms |
2260 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 |
3 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
588 KB |
Output is correct |
34 |
Correct |
1 ms |
320 KB |
Output is correct |
35 |
Correct |
268 ms |
12768 KB |
Output is correct |
36 |
Correct |
238 ms |
18084 KB |
Output is correct |
37 |
Correct |
236 ms |
17424 KB |
Output is correct |
38 |
Correct |
1 ms |
316 KB |
Output is correct |
39 |
Correct |
1 ms |
320 KB |
Output is correct |
40 |
Correct |
0 ms |
212 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 |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
320 KB |
Output is correct |
45 |
Correct |
4 ms |
584 KB |
Output is correct |
46 |
Correct |
7 ms |
848 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
40 ms |
3032 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
123 ms |
8796 KB |
Output is correct |
56 |
Correct |
71 ms |
5072 KB |
Output is correct |
57 |
Correct |
70 ms |
5080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
123 ms |
6052 KB |
Output is correct |
10 |
Correct |
78 ms |
3788 KB |
Output is correct |
11 |
Correct |
59 ms |
3224 KB |
Output is correct |
12 |
Correct |
43 ms |
2260 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 |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
3 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
268 ms |
12768 KB |
Output is correct |
22 |
Correct |
238 ms |
18084 KB |
Output is correct |
23 |
Correct |
236 ms |
17424 KB |
Output is correct |
24 |
Correct |
44 ms |
2816 KB |
Output is correct |
25 |
Correct |
132 ms |
8276 KB |
Output is correct |
26 |
Correct |
25 ms |
2144 KB |
Output is correct |
27 |
Correct |
253 ms |
17472 KB |
Output is correct |
28 |
Correct |
256 ms |
17416 KB |
Output is correct |
29 |
Correct |
254 ms |
17416 KB |
Output is correct |
30 |
Correct |
295 ms |
17372 KB |
Output is correct |
31 |
Correct |
336 ms |
17360 KB |
Output is correct |
32 |
Correct |
298 ms |
12828 KB |
Output is correct |
33 |
Correct |
315 ms |
18020 KB |
Output is correct |
34 |
Correct |
320 ms |
12752 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 |
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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
233 ms |
11672 KB |
Output is correct |
12 |
Correct |
236 ms |
11596 KB |
Output is correct |
13 |
Correct |
232 ms |
11648 KB |
Output is correct |
14 |
Correct |
222 ms |
11632 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 |
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 |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
123 ms |
6052 KB |
Output is correct |
24 |
Correct |
78 ms |
3788 KB |
Output is correct |
25 |
Correct |
59 ms |
3224 KB |
Output is correct |
26 |
Correct |
43 ms |
2260 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 |
3 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
588 KB |
Output is correct |
34 |
Correct |
1 ms |
316 KB |
Output is correct |
35 |
Correct |
1 ms |
320 KB |
Output is correct |
36 |
Correct |
0 ms |
212 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 |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
320 KB |
Output is correct |
41 |
Correct |
4 ms |
584 KB |
Output is correct |
42 |
Correct |
7 ms |
848 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
40 ms |
3032 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
123 ms |
8796 KB |
Output is correct |
52 |
Correct |
71 ms |
5072 KB |
Output is correct |
53 |
Correct |
70 ms |
5080 KB |
Output is correct |
54 |
Correct |
44 ms |
2816 KB |
Output is correct |
55 |
Correct |
132 ms |
8276 KB |
Output is correct |
56 |
Correct |
25 ms |
2144 KB |
Output is correct |
57 |
Correct |
253 ms |
17472 KB |
Output is correct |
58 |
Correct |
256 ms |
17416 KB |
Output is correct |
59 |
Correct |
254 ms |
17416 KB |
Output is correct |
60 |
Correct |
295 ms |
17372 KB |
Output is correct |
61 |
Correct |
336 ms |
17360 KB |
Output is correct |
62 |
Correct |
298 ms |
12828 KB |
Output is correct |
63 |
Correct |
315 ms |
18020 KB |
Output is correct |
64 |
Correct |
320 ms |
12752 KB |
Output is correct |
65 |
Correct |
1 ms |
320 KB |
Output is correct |
66 |
Correct |
268 ms |
12768 KB |
Output is correct |
67 |
Correct |
238 ms |
18084 KB |
Output is correct |
68 |
Correct |
236 ms |
17424 KB |
Output is correct |
69 |
Correct |
30 ms |
1960 KB |
Output is correct |
70 |
Correct |
7 ms |
724 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
44 ms |
2688 KB |
Output is correct |
73 |
Correct |
9 ms |
884 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
253 ms |
17424 KB |
Output is correct |
76 |
Correct |
270 ms |
17472 KB |
Output is correct |
77 |
Correct |
265 ms |
17388 KB |
Output is correct |
78 |
Correct |
308 ms |
17400 KB |
Output is correct |
79 |
Correct |
325 ms |
17348 KB |
Output is correct |
80 |
Correct |
339 ms |
17392 KB |
Output is correct |
81 |
Correct |
291 ms |
15392 KB |
Output is correct |
82 |
Correct |
301 ms |
15396 KB |
Output is correct |