#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <random>
#ifndef LOCAL
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#endif
using namespace std;
using ll = long long;
using ld = long double;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
mt19937_64 mt(418);
void solve();
void init();
int32_t main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#else
freopen("input.txt", "r", stdin);
#endif
// srand(time(0));
init();
cout << fixed << setprecision(20);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
void init() {}
#define int ll
void solve() {
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 = 2e18;
while (r - l > 1) {
ll mid = (r + l) / 2;
ll free = (ll)m * n;
vector<ll> skill(n, 0);
int ok = 1;
for (int i = 0; i < n; i++) {
if (a[i] > b[i]) {
ll have = (mid + a[i] - 1) / a[i];
have = min(have, (ll)m);
skill[i] += a[i] * have;
free -= have;
}
}
for (int i = 0; i < n; i++) {
if (free < 0) {
ok = 0;
}
ll need = mid - skill[i];
if (need > 0) {
ll have = (need + b[i] - 1) / b[i];
skill[i] += b[i] * have;
free -= have;
}
}
if (free >= 0 && ok) {
l = mid;
} else {
r = mid;
}
// cout << "!!! " << r << ' ' << l << '\n';
}
cout << l << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
246 ms |
7492 KB |
Output is correct |
12 |
Correct |
243 ms |
7444 KB |
Output is correct |
13 |
Correct |
152 ms |
7468 KB |
Output is correct |
14 |
Correct |
278 ms |
7488 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
197 ms |
8640 KB |
Output is correct |
17 |
Correct |
163 ms |
13908 KB |
Output is correct |
18 |
Correct |
162 ms |
13300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
197 ms |
8640 KB |
Output is correct |
3 |
Correct |
163 ms |
13908 KB |
Output is correct |
4 |
Correct |
162 ms |
13300 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
82 ms |
3940 KB |
Output is correct |
14 |
Correct |
57 ms |
2652 KB |
Output is correct |
15 |
Correct |
41 ms |
2216 KB |
Output is correct |
16 |
Correct |
33 ms |
1664 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
246 ms |
7492 KB |
Output is correct |
12 |
Correct |
243 ms |
7444 KB |
Output is correct |
13 |
Correct |
152 ms |
7468 KB |
Output is correct |
14 |
Correct |
278 ms |
7488 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
82 ms |
3940 KB |
Output is correct |
24 |
Correct |
57 ms |
2652 KB |
Output is correct |
25 |
Correct |
41 ms |
2216 KB |
Output is correct |
26 |
Correct |
33 ms |
1664 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
3 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
197 ms |
8640 KB |
Output is correct |
36 |
Correct |
163 ms |
13908 KB |
Output is correct |
37 |
Correct |
162 ms |
13300 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
344 KB |
Output is correct |
45 |
Correct |
4 ms |
600 KB |
Output is correct |
46 |
Correct |
7 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
472 KB |
Output is correct |
48 |
Correct |
41 ms |
2652 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
4 ms |
604 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
121 ms |
6820 KB |
Output is correct |
56 |
Correct |
51 ms |
3944 KB |
Output is correct |
57 |
Correct |
92 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
82 ms |
3940 KB |
Output is correct |
10 |
Correct |
57 ms |
2652 KB |
Output is correct |
11 |
Correct |
41 ms |
2216 KB |
Output is correct |
12 |
Correct |
33 ms |
1664 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
197 ms |
8640 KB |
Output is correct |
22 |
Correct |
163 ms |
13908 KB |
Output is correct |
23 |
Correct |
162 ms |
13300 KB |
Output is correct |
24 |
Correct |
32 ms |
2396 KB |
Output is correct |
25 |
Correct |
84 ms |
6212 KB |
Output is correct |
26 |
Correct |
18 ms |
1636 KB |
Output is correct |
27 |
Correct |
163 ms |
13300 KB |
Output is correct |
28 |
Correct |
163 ms |
13304 KB |
Output is correct |
29 |
Correct |
165 ms |
13316 KB |
Output is correct |
30 |
Correct |
177 ms |
13140 KB |
Output is correct |
31 |
Correct |
211 ms |
13136 KB |
Output is correct |
32 |
Correct |
224 ms |
8676 KB |
Output is correct |
33 |
Correct |
226 ms |
13956 KB |
Output is correct |
34 |
Correct |
218 ms |
8528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
246 ms |
7492 KB |
Output is correct |
12 |
Correct |
243 ms |
7444 KB |
Output is correct |
13 |
Correct |
152 ms |
7468 KB |
Output is correct |
14 |
Correct |
278 ms |
7488 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
82 ms |
3940 KB |
Output is correct |
24 |
Correct |
57 ms |
2652 KB |
Output is correct |
25 |
Correct |
41 ms |
2216 KB |
Output is correct |
26 |
Correct |
33 ms |
1664 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
3 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
4 ms |
600 KB |
Output is correct |
42 |
Correct |
7 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
472 KB |
Output is correct |
44 |
Correct |
41 ms |
2652 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
4 ms |
604 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
121 ms |
6820 KB |
Output is correct |
52 |
Correct |
51 ms |
3944 KB |
Output is correct |
53 |
Correct |
92 ms |
3932 KB |
Output is correct |
54 |
Correct |
32 ms |
2396 KB |
Output is correct |
55 |
Correct |
84 ms |
6212 KB |
Output is correct |
56 |
Correct |
18 ms |
1636 KB |
Output is correct |
57 |
Correct |
163 ms |
13300 KB |
Output is correct |
58 |
Correct |
163 ms |
13304 KB |
Output is correct |
59 |
Correct |
165 ms |
13316 KB |
Output is correct |
60 |
Correct |
177 ms |
13140 KB |
Output is correct |
61 |
Correct |
211 ms |
13136 KB |
Output is correct |
62 |
Correct |
224 ms |
8676 KB |
Output is correct |
63 |
Correct |
226 ms |
13956 KB |
Output is correct |
64 |
Correct |
218 ms |
8528 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
197 ms |
8640 KB |
Output is correct |
67 |
Correct |
163 ms |
13908 KB |
Output is correct |
68 |
Correct |
162 ms |
13300 KB |
Output is correct |
69 |
Correct |
26 ms |
1628 KB |
Output is correct |
70 |
Correct |
7 ms |
860 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
34 ms |
2288 KB |
Output is correct |
73 |
Correct |
8 ms |
856 KB |
Output is correct |
74 |
Correct |
1 ms |
344 KB |
Output is correct |
75 |
Correct |
244 ms |
13352 KB |
Output is correct |
76 |
Correct |
236 ms |
13296 KB |
Output is correct |
77 |
Correct |
233 ms |
13352 KB |
Output is correct |
78 |
Correct |
245 ms |
13800 KB |
Output is correct |
79 |
Correct |
235 ms |
13220 KB |
Output is correct |
80 |
Correct |
228 ms |
13220 KB |
Output is correct |
81 |
Correct |
212 ms |
11320 KB |
Output is correct |
82 |
Correct |
357 ms |
11316 KB |
Output is correct |