#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0;i < n;i++)
cin >> a[i];
vector<int> b(n);
for (int i = 0;i < n;i++)
cin >> b[i];
int l = 0, r = 1e18, ans = 0;
auto check = [&](int mid) {
int uk = n * m;
for (int i = 0;i < n;i++) {
int d = 0, t = mid;
if (a[i] > b[i]) {
int x = min(m, (t + a[i] - 1) / a[i]);
t -= x * a[i];
d += x;
}
if (t > 0)
d += (t + b[i] - 1) / b[i];
if (d > uk)
return false;
uk -= d;
}
return true;
};
while (l <= r) {
int mid = l + (r - l) / 2;
if (check(mid)) {
ans = mid;
l = mid + 1;
}
else
r = mid - 1;
}
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
456 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
92 ms |
10948 KB |
Output is correct |
12 |
Correct |
94 ms |
10964 KB |
Output is correct |
13 |
Correct |
76 ms |
8840 KB |
Output is correct |
14 |
Correct |
60 ms |
8788 KB |
Output is correct |
15 |
Correct |
1 ms |
456 KB |
Output is correct |
16 |
Correct |
27 ms |
6236 KB |
Output is correct |
17 |
Correct |
85 ms |
11488 KB |
Output is correct |
18 |
Correct |
88 ms |
10772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Correct |
27 ms |
6236 KB |
Output is correct |
3 |
Correct |
85 ms |
11488 KB |
Output is correct |
4 |
Correct |
88 ms |
10772 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
52 ms |
5460 KB |
Output is correct |
14 |
Correct |
30 ms |
3956 KB |
Output is correct |
15 |
Correct |
21 ms |
3036 KB |
Output is correct |
16 |
Correct |
19 ms |
2576 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
452 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
456 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
92 ms |
10948 KB |
Output is correct |
12 |
Correct |
94 ms |
10964 KB |
Output is correct |
13 |
Correct |
76 ms |
8840 KB |
Output is correct |
14 |
Correct |
60 ms |
8788 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
52 ms |
5460 KB |
Output is correct |
24 |
Correct |
30 ms |
3956 KB |
Output is correct |
25 |
Correct |
21 ms |
3036 KB |
Output is correct |
26 |
Correct |
19 ms |
2576 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
452 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
596 KB |
Output is correct |
34 |
Correct |
1 ms |
456 KB |
Output is correct |
35 |
Correct |
27 ms |
6236 KB |
Output is correct |
36 |
Correct |
85 ms |
11488 KB |
Output is correct |
37 |
Correct |
88 ms |
10772 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
4 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
21 ms |
2268 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
3 ms |
604 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
59 ms |
5460 KB |
Output is correct |
56 |
Correct |
33 ms |
3160 KB |
Output is correct |
57 |
Correct |
30 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
52 ms |
5460 KB |
Output is correct |
10 |
Correct |
30 ms |
3956 KB |
Output is correct |
11 |
Correct |
21 ms |
3036 KB |
Output is correct |
12 |
Correct |
19 ms |
2576 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
452 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
456 KB |
Output is correct |
21 |
Correct |
27 ms |
6236 KB |
Output is correct |
22 |
Correct |
85 ms |
11488 KB |
Output is correct |
23 |
Correct |
88 ms |
10772 KB |
Output is correct |
24 |
Correct |
28 ms |
2096 KB |
Output is correct |
25 |
Correct |
69 ms |
5200 KB |
Output is correct |
26 |
Correct |
11 ms |
1372 KB |
Output is correct |
27 |
Correct |
93 ms |
10896 KB |
Output is correct |
28 |
Correct |
94 ms |
10720 KB |
Output is correct |
29 |
Correct |
97 ms |
10900 KB |
Output is correct |
30 |
Correct |
121 ms |
10960 KB |
Output is correct |
31 |
Correct |
185 ms |
10948 KB |
Output is correct |
32 |
Correct |
115 ms |
6324 KB |
Output is correct |
33 |
Correct |
218 ms |
11604 KB |
Output is correct |
34 |
Correct |
113 ms |
6100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
456 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
92 ms |
10948 KB |
Output is correct |
12 |
Correct |
94 ms |
10964 KB |
Output is correct |
13 |
Correct |
76 ms |
8840 KB |
Output is correct |
14 |
Correct |
60 ms |
8788 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
52 ms |
5460 KB |
Output is correct |
24 |
Correct |
30 ms |
3956 KB |
Output is correct |
25 |
Correct |
21 ms |
3036 KB |
Output is correct |
26 |
Correct |
19 ms |
2576 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
452 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
596 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
4 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
21 ms |
2268 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
3 ms |
604 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
59 ms |
5460 KB |
Output is correct |
52 |
Correct |
33 ms |
3160 KB |
Output is correct |
53 |
Correct |
30 ms |
3164 KB |
Output is correct |
54 |
Correct |
28 ms |
2096 KB |
Output is correct |
55 |
Correct |
69 ms |
5200 KB |
Output is correct |
56 |
Correct |
11 ms |
1372 KB |
Output is correct |
57 |
Correct |
93 ms |
10896 KB |
Output is correct |
58 |
Correct |
94 ms |
10720 KB |
Output is correct |
59 |
Correct |
97 ms |
10900 KB |
Output is correct |
60 |
Correct |
121 ms |
10960 KB |
Output is correct |
61 |
Correct |
185 ms |
10948 KB |
Output is correct |
62 |
Correct |
115 ms |
6324 KB |
Output is correct |
63 |
Correct |
218 ms |
11604 KB |
Output is correct |
64 |
Correct |
113 ms |
6100 KB |
Output is correct |
65 |
Correct |
1 ms |
456 KB |
Output is correct |
66 |
Correct |
27 ms |
6236 KB |
Output is correct |
67 |
Correct |
85 ms |
11488 KB |
Output is correct |
68 |
Correct |
88 ms |
10772 KB |
Output is correct |
69 |
Correct |
22 ms |
1480 KB |
Output is correct |
70 |
Correct |
7 ms |
604 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
32 ms |
1976 KB |
Output is correct |
73 |
Correct |
7 ms |
604 KB |
Output is correct |
74 |
Correct |
1 ms |
348 KB |
Output is correct |
75 |
Correct |
140 ms |
10956 KB |
Output is correct |
76 |
Correct |
113 ms |
10836 KB |
Output is correct |
77 |
Correct |
129 ms |
10916 KB |
Output is correct |
78 |
Correct |
152 ms |
10952 KB |
Output is correct |
79 |
Correct |
224 ms |
10896 KB |
Output is correct |
80 |
Correct |
216 ms |
10956 KB |
Output is correct |
81 |
Correct |
204 ms |
8740 KB |
Output is correct |
82 |
Correct |
214 ms |
8968 KB |
Output is correct |