#include<bits/stdc++.h>
using namespace std;
mt19937 rnd(51);
#define ll long long
#define pb push_back
#define ld long double
const ll INF = 1e18 + 100;
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
ll l = 0, r = INF;
while (r - l > 1) {
ll mid = (r + l) / 2, need = 0, free = 0;
for (int i = 0; i < n; i++) {
if (a[i] > b[i]) {
if ((ll)a[i] * m < mid) {
need += (mid - (ll)a[i] * m + b[i] - 1) / b[i];
need = min(need, INF);
} else {
free += m - (mid + a[i] - 1) / a[i];
}
} else {
need += (mid + b[i] - 1) / b[i];
need = min(need, INF);
free += m;
}
}
if (need <= free) {
l = mid;
} else {
r = mid;
}
}
cout << l << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
212 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
188 ms |
8428 KB |
Output is correct |
12 |
Correct |
172 ms |
8484 KB |
Output is correct |
13 |
Correct |
163 ms |
6492 KB |
Output is correct |
14 |
Correct |
220 ms |
6380 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
193 ms |
3836 KB |
Output is correct |
17 |
Correct |
184 ms |
9252 KB |
Output is correct |
18 |
Correct |
188 ms |
8424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
193 ms |
3836 KB |
Output is correct |
3 |
Correct |
184 ms |
9252 KB |
Output is correct |
4 |
Correct |
188 ms |
8424 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 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 |
324 KB |
Output is correct |
13 |
Correct |
88 ms |
4300 KB |
Output is correct |
14 |
Correct |
65 ms |
3040 KB |
Output is correct |
15 |
Correct |
45 ms |
2360 KB |
Output is correct |
16 |
Correct |
34 ms |
1948 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 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 |
4 ms |
384 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
188 ms |
8428 KB |
Output is correct |
12 |
Correct |
172 ms |
8484 KB |
Output is correct |
13 |
Correct |
163 ms |
6492 KB |
Output is correct |
14 |
Correct |
220 ms |
6380 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 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 |
324 KB |
Output is correct |
23 |
Correct |
88 ms |
4300 KB |
Output is correct |
24 |
Correct |
65 ms |
3040 KB |
Output is correct |
25 |
Correct |
45 ms |
2360 KB |
Output is correct |
26 |
Correct |
34 ms |
1948 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
320 KB |
Output is correct |
35 |
Correct |
193 ms |
3836 KB |
Output is correct |
36 |
Correct |
184 ms |
9252 KB |
Output is correct |
37 |
Correct |
188 ms |
8424 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
324 KB |
Output is correct |
45 |
Correct |
3 ms |
460 KB |
Output is correct |
46 |
Correct |
7 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
30 ms |
1628 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 |
340 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 |
212 KB |
Output is correct |
55 |
Correct |
87 ms |
4288 KB |
Output is correct |
56 |
Correct |
55 ms |
2392 KB |
Output is correct |
57 |
Correct |
71 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 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 |
324 KB |
Output is correct |
9 |
Correct |
88 ms |
4300 KB |
Output is correct |
10 |
Correct |
65 ms |
3040 KB |
Output is correct |
11 |
Correct |
45 ms |
2360 KB |
Output is correct |
12 |
Correct |
34 ms |
1948 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 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 |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
193 ms |
3836 KB |
Output is correct |
22 |
Correct |
184 ms |
9252 KB |
Output is correct |
23 |
Correct |
188 ms |
8424 KB |
Output is correct |
24 |
Correct |
33 ms |
1580 KB |
Output is correct |
25 |
Correct |
86 ms |
3932 KB |
Output is correct |
26 |
Correct |
20 ms |
1064 KB |
Output is correct |
27 |
Correct |
181 ms |
8396 KB |
Output is correct |
28 |
Correct |
169 ms |
8428 KB |
Output is correct |
29 |
Correct |
171 ms |
8420 KB |
Output is correct |
30 |
Correct |
204 ms |
8612 KB |
Output is correct |
31 |
Correct |
220 ms |
8420 KB |
Output is correct |
32 |
Correct |
221 ms |
3812 KB |
Output is correct |
33 |
Correct |
264 ms |
9076 KB |
Output is correct |
34 |
Correct |
218 ms |
3836 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 |
212 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
188 ms |
8428 KB |
Output is correct |
12 |
Correct |
172 ms |
8484 KB |
Output is correct |
13 |
Correct |
163 ms |
6492 KB |
Output is correct |
14 |
Correct |
220 ms |
6380 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 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 |
324 KB |
Output is correct |
23 |
Correct |
88 ms |
4300 KB |
Output is correct |
24 |
Correct |
65 ms |
3040 KB |
Output is correct |
25 |
Correct |
45 ms |
2360 KB |
Output is correct |
26 |
Correct |
34 ms |
1948 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
324 KB |
Output is correct |
41 |
Correct |
3 ms |
460 KB |
Output is correct |
42 |
Correct |
7 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
30 ms |
1628 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 |
340 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 |
212 KB |
Output is correct |
51 |
Correct |
87 ms |
4288 KB |
Output is correct |
52 |
Correct |
55 ms |
2392 KB |
Output is correct |
53 |
Correct |
71 ms |
2388 KB |
Output is correct |
54 |
Correct |
33 ms |
1580 KB |
Output is correct |
55 |
Correct |
86 ms |
3932 KB |
Output is correct |
56 |
Correct |
20 ms |
1064 KB |
Output is correct |
57 |
Correct |
181 ms |
8396 KB |
Output is correct |
58 |
Correct |
169 ms |
8428 KB |
Output is correct |
59 |
Correct |
171 ms |
8420 KB |
Output is correct |
60 |
Correct |
204 ms |
8612 KB |
Output is correct |
61 |
Correct |
220 ms |
8420 KB |
Output is correct |
62 |
Correct |
221 ms |
3812 KB |
Output is correct |
63 |
Correct |
264 ms |
9076 KB |
Output is correct |
64 |
Correct |
218 ms |
3836 KB |
Output is correct |
65 |
Correct |
1 ms |
320 KB |
Output is correct |
66 |
Correct |
193 ms |
3836 KB |
Output is correct |
67 |
Correct |
184 ms |
9252 KB |
Output is correct |
68 |
Correct |
188 ms |
8424 KB |
Output is correct |
69 |
Correct |
25 ms |
1184 KB |
Output is correct |
70 |
Correct |
8 ms |
468 KB |
Output is correct |
71 |
Correct |
1 ms |
324 KB |
Output is correct |
72 |
Correct |
33 ms |
1492 KB |
Output is correct |
73 |
Correct |
7 ms |
592 KB |
Output is correct |
74 |
Correct |
1 ms |
336 KB |
Output is correct |
75 |
Correct |
186 ms |
8476 KB |
Output is correct |
76 |
Correct |
194 ms |
8544 KB |
Output is correct |
77 |
Correct |
185 ms |
8412 KB |
Output is correct |
78 |
Correct |
195 ms |
8476 KB |
Output is correct |
79 |
Correct |
230 ms |
8420 KB |
Output is correct |
80 |
Correct |
237 ms |
8468 KB |
Output is correct |
81 |
Correct |
221 ms |
6488 KB |
Output is correct |
82 |
Correct |
220 ms |
6488 KB |
Output is correct |