#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
void Solve()
{
int n, m; cin >> n >> m;
vector <int> a(n), b(n);
for (auto &x : a) cin >> x;
for (auto &x : b) cin >> x;
int l = 0, r = INF;
while (r != l){
int mid = (l + r + 1) / 2;
int use = 0, need = 0;
for (int i = 0; i < n; i++){
if (a[i] <= b[i]) {
need += (mid + b[i] - 1) / b[i];
if (use + need > n * m) break;
continue;
}
int o = (mid + a[i] - 1) / a[i];
int o1 = 0;
if (o > m){
o = m;
int ex = mid - a[i] * o;
o1 = (ex + b[i] - 1) / b[i];
//assert(o1 >= 0);
}
int ex = a[i] * o + b[i] * o1 - mid;
assert(ex >= 0);
int sw = ex / (a[i] - b[i]);
if (sw > o) sw = o;
o -= sw;
o1 += sw;
use += o;
need += o1;
if (use + need > n * m) break;
}
if (use + need > n * m) r = mid - 1;
else l = mid;
}
cout << l << "\n";
}
int32_t main()
{
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
//cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
1 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 |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
100 ms |
5016 KB |
Output is correct |
12 |
Correct |
103 ms |
5008 KB |
Output is correct |
13 |
Correct |
66 ms |
4948 KB |
Output is correct |
14 |
Correct |
78 ms |
4948 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
27 ms |
5028 KB |
Output is correct |
17 |
Correct |
93 ms |
4948 KB |
Output is correct |
18 |
Correct |
89 ms |
5012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
27 ms |
5028 KB |
Output is correct |
3 |
Correct |
93 ms |
4948 KB |
Output is correct |
4 |
Correct |
89 ms |
5012 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
42 ms |
2668 KB |
Output is correct |
14 |
Correct |
28 ms |
1876 KB |
Output is correct |
15 |
Correct |
21 ms |
1492 KB |
Output is correct |
16 |
Correct |
21 ms |
1280 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 |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 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 |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
100 ms |
5016 KB |
Output is correct |
12 |
Correct |
103 ms |
5008 KB |
Output is correct |
13 |
Correct |
66 ms |
4948 KB |
Output is correct |
14 |
Correct |
78 ms |
4948 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 |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
42 ms |
2668 KB |
Output is correct |
24 |
Correct |
28 ms |
1876 KB |
Output is correct |
25 |
Correct |
21 ms |
1492 KB |
Output is correct |
26 |
Correct |
21 ms |
1280 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 |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
27 ms |
5028 KB |
Output is correct |
36 |
Correct |
93 ms |
4948 KB |
Output is correct |
37 |
Correct |
89 ms |
5012 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 |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
3 ms |
340 KB |
Output is correct |
46 |
Correct |
4 ms |
456 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
19 ms |
1148 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
2 ms |
340 KB |
Output is correct |
52 |
Correct |
0 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 |
54 ms |
2644 KB |
Output is correct |
56 |
Correct |
26 ms |
1876 KB |
Output is correct |
57 |
Correct |
29 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
42 ms |
2668 KB |
Output is correct |
10 |
Correct |
28 ms |
1876 KB |
Output is correct |
11 |
Correct |
21 ms |
1492 KB |
Output is correct |
12 |
Correct |
21 ms |
1280 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 |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
27 ms |
5028 KB |
Output is correct |
22 |
Correct |
93 ms |
4948 KB |
Output is correct |
23 |
Correct |
89 ms |
5012 KB |
Output is correct |
24 |
Correct |
26 ms |
980 KB |
Output is correct |
25 |
Correct |
62 ms |
4980 KB |
Output is correct |
26 |
Correct |
11 ms |
1328 KB |
Output is correct |
27 |
Correct |
86 ms |
8844 KB |
Output is correct |
28 |
Correct |
92 ms |
8856 KB |
Output is correct |
29 |
Correct |
90 ms |
8780 KB |
Output is correct |
30 |
Correct |
110 ms |
8764 KB |
Output is correct |
31 |
Correct |
185 ms |
8780 KB |
Output is correct |
32 |
Correct |
106 ms |
6100 KB |
Output is correct |
33 |
Correct |
212 ms |
8852 KB |
Output is correct |
34 |
Correct |
105 ms |
6100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 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 |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
100 ms |
5016 KB |
Output is correct |
12 |
Correct |
103 ms |
5008 KB |
Output is correct |
13 |
Correct |
66 ms |
4948 KB |
Output is correct |
14 |
Correct |
78 ms |
4948 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 |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
42 ms |
2668 KB |
Output is correct |
24 |
Correct |
28 ms |
1876 KB |
Output is correct |
25 |
Correct |
21 ms |
1492 KB |
Output is correct |
26 |
Correct |
21 ms |
1280 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 |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
3 ms |
340 KB |
Output is correct |
42 |
Correct |
4 ms |
456 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
19 ms |
1148 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
2 ms |
340 KB |
Output is correct |
48 |
Correct |
0 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 |
54 ms |
2644 KB |
Output is correct |
52 |
Correct |
26 ms |
1876 KB |
Output is correct |
53 |
Correct |
29 ms |
1876 KB |
Output is correct |
54 |
Correct |
26 ms |
980 KB |
Output is correct |
55 |
Correct |
62 ms |
4980 KB |
Output is correct |
56 |
Correct |
11 ms |
1328 KB |
Output is correct |
57 |
Correct |
86 ms |
8844 KB |
Output is correct |
58 |
Correct |
92 ms |
8856 KB |
Output is correct |
59 |
Correct |
90 ms |
8780 KB |
Output is correct |
60 |
Correct |
110 ms |
8764 KB |
Output is correct |
61 |
Correct |
185 ms |
8780 KB |
Output is correct |
62 |
Correct |
106 ms |
6100 KB |
Output is correct |
63 |
Correct |
212 ms |
8852 KB |
Output is correct |
64 |
Correct |
105 ms |
6100 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
27 ms |
5028 KB |
Output is correct |
67 |
Correct |
93 ms |
4948 KB |
Output is correct |
68 |
Correct |
89 ms |
5012 KB |
Output is correct |
69 |
Correct |
25 ms |
1492 KB |
Output is correct |
70 |
Correct |
7 ms |
596 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
35 ms |
1768 KB |
Output is correct |
73 |
Correct |
9 ms |
592 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
133 ms |
8848 KB |
Output is correct |
76 |
Correct |
131 ms |
8852 KB |
Output is correct |
77 |
Correct |
145 ms |
8920 KB |
Output is correct |
78 |
Correct |
184 ms |
8848 KB |
Output is correct |
79 |
Correct |
242 ms |
8732 KB |
Output is correct |
80 |
Correct |
263 ms |
8932 KB |
Output is correct |
81 |
Correct |
196 ms |
8828 KB |
Output is correct |
82 |
Correct |
284 ms |
8828 KB |
Output is correct |