#include "bits/stdc++.h"
#include <functional>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<ll> a(n), b(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]);
}
auto check = [&](ll mid) -> bool {
ll freeLesson = 0;
for (int i = 0; i < n; i++) {
ll numLesson = mid / a[i] + ((mid % a[i] == 0) ? 0 : 1);
// cout << "@@@" << i << " " << a[i] << " " << numLesson << endl;
if (numLesson < m) {
freeLesson += m - numLesson;
}
}
// cout << mid << " " << freeLesson << endl;
for (int i = 0; i < n; i++) {
ll numLesson = mid / a[i] + ((mid % a[i] == 0) ? 0 : 1);
if (numLesson > m) {
ll stillNeed = max(0ll, mid - m * a[i]);
freeLesson -= stillNeed / b[i] + ((stillNeed % b[i] == 0) ? 0 : 1);
}
if (freeLesson < 0) return false;
}
return true;
};
ll l = 0;
ll r = 1e18;
while (l <= r) {
ll mid = (l + r) / 2;
if (check(mid)) {
l = mid + 1;
}
else {
r = mid - 1;
}
}
cout << r << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
480 KB |
Output is correct |
11 |
Correct |
262 ms |
10756 KB |
Output is correct |
12 |
Correct |
232 ms |
10808 KB |
Output is correct |
13 |
Correct |
234 ms |
8820 KB |
Output is correct |
14 |
Correct |
232 ms |
8824 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
230 ms |
6184 KB |
Output is correct |
17 |
Correct |
259 ms |
11460 KB |
Output is correct |
18 |
Correct |
244 ms |
10892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
230 ms |
6184 KB |
Output is correct |
3 |
Correct |
259 ms |
11460 KB |
Output is correct |
4 |
Correct |
244 ms |
10892 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
232 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
121 ms |
5564 KB |
Output is correct |
14 |
Correct |
88 ms |
3824 KB |
Output is correct |
15 |
Correct |
64 ms |
2944 KB |
Output is correct |
16 |
Correct |
63 ms |
2420 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
4 ms |
340 KB |
Output is correct |
23 |
Correct |
6 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
480 KB |
Output is correct |
11 |
Correct |
262 ms |
10756 KB |
Output is correct |
12 |
Correct |
232 ms |
10808 KB |
Output is correct |
13 |
Correct |
234 ms |
8820 KB |
Output is correct |
14 |
Correct |
232 ms |
8824 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
232 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
121 ms |
5564 KB |
Output is correct |
24 |
Correct |
88 ms |
3824 KB |
Output is correct |
25 |
Correct |
64 ms |
2944 KB |
Output is correct |
26 |
Correct |
63 ms |
2420 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
230 ms |
6184 KB |
Output is correct |
36 |
Correct |
259 ms |
11460 KB |
Output is correct |
37 |
Correct |
244 ms |
10892 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
320 KB |
Output is correct |
40 |
Correct |
1 ms |
252 KB |
Output is correct |
41 |
Correct |
1 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 |
212 KB |
Output is correct |
45 |
Correct |
6 ms |
468 KB |
Output is correct |
46 |
Correct |
19 ms |
716 KB |
Output is correct |
47 |
Correct |
2 ms |
340 KB |
Output is correct |
48 |
Correct |
46 ms |
2064 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
6 ms |
484 KB |
Output is correct |
52 |
Correct |
1 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 |
132 ms |
5444 KB |
Output is correct |
56 |
Correct |
64 ms |
3164 KB |
Output is correct |
57 |
Correct |
74 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
232 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
121 ms |
5564 KB |
Output is correct |
10 |
Correct |
88 ms |
3824 KB |
Output is correct |
11 |
Correct |
64 ms |
2944 KB |
Output is correct |
12 |
Correct |
63 ms |
2420 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
4 ms |
340 KB |
Output is correct |
19 |
Correct |
6 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
230 ms |
6184 KB |
Output is correct |
22 |
Correct |
259 ms |
11460 KB |
Output is correct |
23 |
Correct |
244 ms |
10892 KB |
Output is correct |
24 |
Correct |
70 ms |
1944 KB |
Output is correct |
25 |
Correct |
183 ms |
5032 KB |
Output is correct |
26 |
Correct |
34 ms |
1328 KB |
Output is correct |
27 |
Correct |
258 ms |
10820 KB |
Output is correct |
28 |
Correct |
231 ms |
10824 KB |
Output is correct |
29 |
Correct |
289 ms |
10760 KB |
Output is correct |
30 |
Correct |
327 ms |
10764 KB |
Output is correct |
31 |
Correct |
413 ms |
10816 KB |
Output is correct |
32 |
Correct |
320 ms |
6184 KB |
Output is correct |
33 |
Correct |
493 ms |
11460 KB |
Output is correct |
34 |
Correct |
326 ms |
6184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
480 KB |
Output is correct |
11 |
Correct |
262 ms |
10756 KB |
Output is correct |
12 |
Correct |
232 ms |
10808 KB |
Output is correct |
13 |
Correct |
234 ms |
8820 KB |
Output is correct |
14 |
Correct |
232 ms |
8824 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
232 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
121 ms |
5564 KB |
Output is correct |
24 |
Correct |
88 ms |
3824 KB |
Output is correct |
25 |
Correct |
64 ms |
2944 KB |
Output is correct |
26 |
Correct |
63 ms |
2420 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
320 KB |
Output is correct |
36 |
Correct |
1 ms |
252 KB |
Output is correct |
37 |
Correct |
1 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 |
212 KB |
Output is correct |
41 |
Correct |
6 ms |
468 KB |
Output is correct |
42 |
Correct |
19 ms |
716 KB |
Output is correct |
43 |
Correct |
2 ms |
340 KB |
Output is correct |
44 |
Correct |
46 ms |
2064 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
6 ms |
484 KB |
Output is correct |
48 |
Correct |
1 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 |
132 ms |
5444 KB |
Output is correct |
52 |
Correct |
64 ms |
3164 KB |
Output is correct |
53 |
Correct |
74 ms |
3164 KB |
Output is correct |
54 |
Correct |
70 ms |
1944 KB |
Output is correct |
55 |
Correct |
183 ms |
5032 KB |
Output is correct |
56 |
Correct |
34 ms |
1328 KB |
Output is correct |
57 |
Correct |
258 ms |
10820 KB |
Output is correct |
58 |
Correct |
231 ms |
10824 KB |
Output is correct |
59 |
Correct |
289 ms |
10760 KB |
Output is correct |
60 |
Correct |
327 ms |
10764 KB |
Output is correct |
61 |
Correct |
413 ms |
10816 KB |
Output is correct |
62 |
Correct |
320 ms |
6184 KB |
Output is correct |
63 |
Correct |
493 ms |
11460 KB |
Output is correct |
64 |
Correct |
326 ms |
6184 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
230 ms |
6184 KB |
Output is correct |
67 |
Correct |
259 ms |
11460 KB |
Output is correct |
68 |
Correct |
244 ms |
10892 KB |
Output is correct |
69 |
Correct |
48 ms |
1476 KB |
Output is correct |
70 |
Correct |
12 ms |
556 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
65 ms |
1824 KB |
Output is correct |
73 |
Correct |
17 ms |
588 KB |
Output is correct |
74 |
Correct |
2 ms |
340 KB |
Output is correct |
75 |
Correct |
257 ms |
10816 KB |
Output is correct |
76 |
Correct |
281 ms |
10944 KB |
Output is correct |
77 |
Correct |
280 ms |
10816 KB |
Output is correct |
78 |
Correct |
347 ms |
10832 KB |
Output is correct |
79 |
Correct |
490 ms |
10820 KB |
Output is correct |
80 |
Correct |
482 ms |
10816 KB |
Output is correct |
81 |
Correct |
444 ms |
8836 KB |
Output is correct |
82 |
Correct |
496 ms |
8856 KB |
Output is correct |