#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define nemeshay ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define allr(pon) pon.rbegin(), pon.rend()
#define all(pon) pon.begin(), pon.end()
#define nosolve cout << "-1\n"
#define YES cout << "YES\n"
#define Yes cout << "Yes\n"
#define pii pair <int, int>
#define OK cout << "OK\n"
#define Ok cout << "Ok\n"
#define NO cout << "NO\n"
#define No cout << "No\n"
#define pf push_front
#define int long long
#define pb push_back
#define sigma signed
#define sc second
#define fr first
using namespace __gnu_pbds;
using namespace std;
const int N = 1e6 + 20, INF = 1e9 + 17;
int a[N], b[N];
sigma main(){
nemeshay
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
auto check = [&](int med) {
int t = 0;
for (int i = 0; i < n; i++) {
if (b[i] > a[i]) t += (med + b[i] - 1) / b[i];
else {
if (a[i] * m >= med) t += (med + a[i] - 1) / a[i];
else t += (med - a[i] * m + b[i] - 1) / b[i] + m;
}
if (t > n * m) return 0;
}
if (t <= n * m) return 1;
return 0;
};
int l = 0, r = 1e18;
while (r - l > 1) {
int med = l + r >> 1;
if (check(med)) l = med;
else r = med;
}
if (check(r)) cout << r;
else cout << l;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:47:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
47 | int med = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
79 ms |
8660 KB |
Output is correct |
12 |
Correct |
83 ms |
8792 KB |
Output is correct |
13 |
Correct |
46 ms |
8784 KB |
Output is correct |
14 |
Correct |
40 ms |
8792 KB |
Output is correct |
15 |
Correct |
0 ms |
2392 KB |
Output is correct |
16 |
Correct |
20 ms |
8792 KB |
Output is correct |
17 |
Correct |
57 ms |
8580 KB |
Output is correct |
18 |
Correct |
57 ms |
8788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
20 ms |
8792 KB |
Output is correct |
3 |
Correct |
57 ms |
8580 KB |
Output is correct |
4 |
Correct |
57 ms |
8788 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
29 ms |
6804 KB |
Output is correct |
14 |
Correct |
20 ms |
6800 KB |
Output is correct |
15 |
Correct |
15 ms |
6804 KB |
Output is correct |
16 |
Correct |
12 ms |
4572 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2520 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
2 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
79 ms |
8660 KB |
Output is correct |
12 |
Correct |
83 ms |
8792 KB |
Output is correct |
13 |
Correct |
46 ms |
8784 KB |
Output is correct |
14 |
Correct |
40 ms |
8792 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2392 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
29 ms |
6804 KB |
Output is correct |
24 |
Correct |
20 ms |
6800 KB |
Output is correct |
25 |
Correct |
15 ms |
6804 KB |
Output is correct |
26 |
Correct |
12 ms |
4572 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2520 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
0 ms |
2396 KB |
Output is correct |
31 |
Correct |
0 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2392 KB |
Output is correct |
34 |
Correct |
0 ms |
2392 KB |
Output is correct |
35 |
Correct |
20 ms |
8792 KB |
Output is correct |
36 |
Correct |
57 ms |
8580 KB |
Output is correct |
37 |
Correct |
57 ms |
8788 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
2 ms |
2396 KB |
Output is correct |
46 |
Correct |
3 ms |
2396 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
14 ms |
4756 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
2 ms |
2396 KB |
Output is correct |
52 |
Correct |
0 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
54 |
Correct |
1 ms |
2396 KB |
Output is correct |
55 |
Correct |
46 ms |
6624 KB |
Output is correct |
56 |
Correct |
17 ms |
6748 KB |
Output is correct |
57 |
Correct |
14 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
29 ms |
6804 KB |
Output is correct |
10 |
Correct |
20 ms |
6800 KB |
Output is correct |
11 |
Correct |
15 ms |
6804 KB |
Output is correct |
12 |
Correct |
12 ms |
4572 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2520 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2392 KB |
Output is correct |
20 |
Correct |
0 ms |
2392 KB |
Output is correct |
21 |
Correct |
20 ms |
8792 KB |
Output is correct |
22 |
Correct |
57 ms |
8580 KB |
Output is correct |
23 |
Correct |
57 ms |
8788 KB |
Output is correct |
24 |
Correct |
12 ms |
4700 KB |
Output is correct |
25 |
Correct |
32 ms |
6628 KB |
Output is correct |
26 |
Correct |
7 ms |
4700 KB |
Output is correct |
27 |
Correct |
57 ms |
8788 KB |
Output is correct |
28 |
Correct |
61 ms |
8788 KB |
Output is correct |
29 |
Correct |
60 ms |
8588 KB |
Output is correct |
30 |
Correct |
67 ms |
8832 KB |
Output is correct |
31 |
Correct |
76 ms |
8832 KB |
Output is correct |
32 |
Correct |
41 ms |
8792 KB |
Output is correct |
33 |
Correct |
81 ms |
8784 KB |
Output is correct |
34 |
Correct |
48 ms |
8664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
79 ms |
8660 KB |
Output is correct |
12 |
Correct |
83 ms |
8792 KB |
Output is correct |
13 |
Correct |
46 ms |
8784 KB |
Output is correct |
14 |
Correct |
40 ms |
8792 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2392 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
29 ms |
6804 KB |
Output is correct |
24 |
Correct |
20 ms |
6800 KB |
Output is correct |
25 |
Correct |
15 ms |
6804 KB |
Output is correct |
26 |
Correct |
12 ms |
4572 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2520 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
0 ms |
2396 KB |
Output is correct |
31 |
Correct |
0 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
0 ms |
2396 KB |
Output is correct |
36 |
Correct |
0 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
0 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
2396 KB |
Output is correct |
42 |
Correct |
3 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
14 ms |
4756 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
2 ms |
2396 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
46 ms |
6624 KB |
Output is correct |
52 |
Correct |
17 ms |
6748 KB |
Output is correct |
53 |
Correct |
14 ms |
6748 KB |
Output is correct |
54 |
Correct |
12 ms |
4700 KB |
Output is correct |
55 |
Correct |
32 ms |
6628 KB |
Output is correct |
56 |
Correct |
7 ms |
4700 KB |
Output is correct |
57 |
Correct |
57 ms |
8788 KB |
Output is correct |
58 |
Correct |
61 ms |
8788 KB |
Output is correct |
59 |
Correct |
60 ms |
8588 KB |
Output is correct |
60 |
Correct |
67 ms |
8832 KB |
Output is correct |
61 |
Correct |
76 ms |
8832 KB |
Output is correct |
62 |
Correct |
41 ms |
8792 KB |
Output is correct |
63 |
Correct |
81 ms |
8784 KB |
Output is correct |
64 |
Correct |
48 ms |
8664 KB |
Output is correct |
65 |
Correct |
0 ms |
2392 KB |
Output is correct |
66 |
Correct |
20 ms |
8792 KB |
Output is correct |
67 |
Correct |
57 ms |
8580 KB |
Output is correct |
68 |
Correct |
57 ms |
8788 KB |
Output is correct |
69 |
Correct |
12 ms |
4696 KB |
Output is correct |
70 |
Correct |
2 ms |
2396 KB |
Output is correct |
71 |
Correct |
1 ms |
2396 KB |
Output is correct |
72 |
Correct |
17 ms |
4564 KB |
Output is correct |
73 |
Correct |
3 ms |
2396 KB |
Output is correct |
74 |
Correct |
1 ms |
2396 KB |
Output is correct |
75 |
Correct |
85 ms |
8848 KB |
Output is correct |
76 |
Correct |
89 ms |
8792 KB |
Output is correct |
77 |
Correct |
100 ms |
8788 KB |
Output is correct |
78 |
Correct |
106 ms |
8596 KB |
Output is correct |
79 |
Correct |
120 ms |
8788 KB |
Output is correct |
80 |
Correct |
120 ms |
8832 KB |
Output is correct |
81 |
Correct |
71 ms |
8836 KB |
Output is correct |
82 |
Correct |
71 ms |
8836 KB |
Output is correct |