#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll; typedef pair<int, int> pii;
#define pb emplace_back
#define AI(x) begin(x),end(x)
#define ff first
#define ss second
#ifdef OWO
#define debug(args...) LKJ("\033[0;32m[ " + string(#args) + " ]\033[0m", args)
template<class I> void LKJ(I&&x) { cerr << x << endl; }
template<class I, class...T> void LKJ(I&&x, T&&...t) { cerr << x << ", "; LKJ(t...); }
template<class I> void OI(I a, I b) { while (a < b) cerr << *a << " \n"[next(a) == b]; }
#else
#define debug(...) 0
#define OI(...) 0
#endif
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll N, M; cin >> N >> M;
vector<ll> A(N), B(N);
for (ll &i: A) cin >> i;
for (ll &i: B) cin >> i;
ll ans = 0;
for (ll l = (1ll << 60); l > 0; l >>= 1) {
ll threshold = ans + l;
debug(threshold);
ll empty = N * M;
for (int i = 0; i < N and empty >= 0; ++i) {
ll tmp = threshold;
if (A[i] >= B[i]) {
ll chooseA = (tmp + A[i] - 1) / A[i];
chooseA = min(chooseA, M);
tmp -= A[i] * chooseA;
empty -= chooseA;
//debug(i, chooseA);
}
if (tmp > 0) {
ll chooseB = (tmp + B[i] - 1) / B[i];
//debug(i, chooseB);
empty -= chooseB;
}
}
if (empty >= 0) ans = threshold;
}
cout << ans << '\n';
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:14:20: warning: statement has no effect [-Wunused-value]
14 | #define debug(...) 0
| ^
Main.cpp:29:3: note: in expansion of macro 'debug'
29 | debug(threshold);
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
128 ms |
5000 KB |
Output is correct |
12 |
Correct |
100 ms |
4940 KB |
Output is correct |
13 |
Correct |
83 ms |
4940 KB |
Output is correct |
14 |
Correct |
75 ms |
5012 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
32 ms |
4940 KB |
Output is correct |
17 |
Correct |
117 ms |
4940 KB |
Output is correct |
18 |
Correct |
94 ms |
4940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
32 ms |
4940 KB |
Output is correct |
3 |
Correct |
117 ms |
4940 KB |
Output is correct |
4 |
Correct |
94 ms |
4940 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
51 ms |
2636 KB |
Output is correct |
14 |
Correct |
33 ms |
1868 KB |
Output is correct |
15 |
Correct |
24 ms |
1484 KB |
Output is correct |
16 |
Correct |
22 ms |
1228 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
128 ms |
5000 KB |
Output is correct |
12 |
Correct |
100 ms |
4940 KB |
Output is correct |
13 |
Correct |
83 ms |
4940 KB |
Output is correct |
14 |
Correct |
75 ms |
5012 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
51 ms |
2636 KB |
Output is correct |
24 |
Correct |
33 ms |
1868 KB |
Output is correct |
25 |
Correct |
24 ms |
1484 KB |
Output is correct |
26 |
Correct |
22 ms |
1228 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
4 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
32 ms |
4940 KB |
Output is correct |
36 |
Correct |
117 ms |
4940 KB |
Output is correct |
37 |
Correct |
94 ms |
4940 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
0 ms |
204 KB |
Output is correct |
45 |
Correct |
3 ms |
332 KB |
Output is correct |
46 |
Correct |
4 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
18 ms |
1100 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
2 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
204 KB |
Output is correct |
53 |
Correct |
0 ms |
204 KB |
Output is correct |
54 |
Correct |
1 ms |
204 KB |
Output is correct |
55 |
Correct |
63 ms |
2636 KB |
Output is correct |
56 |
Correct |
32 ms |
1868 KB |
Output is correct |
57 |
Correct |
25 ms |
1868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
51 ms |
2636 KB |
Output is correct |
10 |
Correct |
33 ms |
1868 KB |
Output is correct |
11 |
Correct |
24 ms |
1484 KB |
Output is correct |
12 |
Correct |
22 ms |
1228 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
32 ms |
4940 KB |
Output is correct |
22 |
Correct |
117 ms |
4940 KB |
Output is correct |
23 |
Correct |
94 ms |
4940 KB |
Output is correct |
24 |
Correct |
32 ms |
1040 KB |
Output is correct |
25 |
Correct |
78 ms |
2380 KB |
Output is correct |
26 |
Correct |
17 ms |
716 KB |
Output is correct |
27 |
Correct |
93 ms |
4940 KB |
Output is correct |
28 |
Correct |
105 ms |
4940 KB |
Output is correct |
29 |
Correct |
109 ms |
4940 KB |
Output is correct |
30 |
Correct |
143 ms |
4996 KB |
Output is correct |
31 |
Correct |
222 ms |
5000 KB |
Output is correct |
32 |
Correct |
158 ms |
5000 KB |
Output is correct |
33 |
Correct |
308 ms |
5000 KB |
Output is correct |
34 |
Correct |
159 ms |
5000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
128 ms |
5000 KB |
Output is correct |
12 |
Correct |
100 ms |
4940 KB |
Output is correct |
13 |
Correct |
83 ms |
4940 KB |
Output is correct |
14 |
Correct |
75 ms |
5012 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
51 ms |
2636 KB |
Output is correct |
24 |
Correct |
33 ms |
1868 KB |
Output is correct |
25 |
Correct |
24 ms |
1484 KB |
Output is correct |
26 |
Correct |
22 ms |
1228 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
4 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
3 ms |
332 KB |
Output is correct |
42 |
Correct |
4 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
18 ms |
1100 KB |
Output is correct |
45 |
Correct |
0 ms |
204 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
2 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
63 ms |
2636 KB |
Output is correct |
52 |
Correct |
32 ms |
1868 KB |
Output is correct |
53 |
Correct |
25 ms |
1868 KB |
Output is correct |
54 |
Correct |
32 ms |
1040 KB |
Output is correct |
55 |
Correct |
78 ms |
2380 KB |
Output is correct |
56 |
Correct |
17 ms |
716 KB |
Output is correct |
57 |
Correct |
93 ms |
4940 KB |
Output is correct |
58 |
Correct |
105 ms |
4940 KB |
Output is correct |
59 |
Correct |
109 ms |
4940 KB |
Output is correct |
60 |
Correct |
143 ms |
4996 KB |
Output is correct |
61 |
Correct |
222 ms |
5000 KB |
Output is correct |
62 |
Correct |
158 ms |
5000 KB |
Output is correct |
63 |
Correct |
308 ms |
5000 KB |
Output is correct |
64 |
Correct |
159 ms |
5000 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
32 ms |
4940 KB |
Output is correct |
67 |
Correct |
117 ms |
4940 KB |
Output is correct |
68 |
Correct |
94 ms |
4940 KB |
Output is correct |
69 |
Correct |
23 ms |
836 KB |
Output is correct |
70 |
Correct |
6 ms |
332 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Correct |
34 ms |
996 KB |
Output is correct |
73 |
Correct |
7 ms |
460 KB |
Output is correct |
74 |
Correct |
1 ms |
204 KB |
Output is correct |
75 |
Correct |
129 ms |
4972 KB |
Output is correct |
76 |
Correct |
120 ms |
4940 KB |
Output is correct |
77 |
Correct |
132 ms |
4940 KB |
Output is correct |
78 |
Correct |
173 ms |
5004 KB |
Output is correct |
79 |
Correct |
232 ms |
4996 KB |
Output is correct |
80 |
Correct |
228 ms |
4992 KB |
Output is correct |
81 |
Correct |
225 ms |
5060 KB |
Output is correct |
82 |
Correct |
237 ms |
4940 KB |
Output is correct |