#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))
using namespace std;
const ll LINF = 1e18;
const int mxN = 1e6+10, INF = 2e9;
ll n, m, a[mxN], b[mxN];
bool Check(ll k){
ll cnt = 0;
for (int i = 0; i < n; i++){
ll cur = k;
if (a[i] > b[i]){
ll x = (k + a[i] - 1)/a[i];
smin(x, m);
cur -= min(cur, x*a[i]);
cnt += x;
}
ll x = (cur + b[i] - 1)/b[i];
cnt += x;
if (cnt > n*m) return 0;
}
return cnt <= n*m;
}
void Solve(){
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
ll l = 1, r = LINF, ans = 0;
while (l <= r){
ll k = (l + r + 1)>>1;
if (Check(k)){
ans = k;
l = k + 1;
}
else r = k - 1;
}
cout << ans << en;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0); cerr.tie(0);
cout << setprecision(12) << fixed;
cerr << setprecision(12) << fixed;
cerr << "Started!" << endl;
int t = 1;
//cin >> t;
while (t--)
Solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
440 KB |
Output is correct |
11 |
Correct |
118 ms |
10816 KB |
Output is correct |
12 |
Correct |
119 ms |
10812 KB |
Output is correct |
13 |
Correct |
85 ms |
8780 KB |
Output is correct |
14 |
Correct |
95 ms |
8752 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
31 ms |
6120 KB |
Output is correct |
17 |
Correct |
110 ms |
11468 KB |
Output is correct |
18 |
Correct |
98 ms |
10872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
31 ms |
6120 KB |
Output is correct |
3 |
Correct |
110 ms |
11468 KB |
Output is correct |
4 |
Correct |
98 ms |
10872 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
52 ms |
5468 KB |
Output is correct |
14 |
Correct |
33 ms |
3788 KB |
Output is correct |
15 |
Correct |
24 ms |
2948 KB |
Output is correct |
16 |
Correct |
22 ms |
2420 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
440 KB |
Output is correct |
11 |
Correct |
118 ms |
10816 KB |
Output is correct |
12 |
Correct |
119 ms |
10812 KB |
Output is correct |
13 |
Correct |
85 ms |
8780 KB |
Output is correct |
14 |
Correct |
95 ms |
8752 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
52 ms |
5468 KB |
Output is correct |
24 |
Correct |
33 ms |
3788 KB |
Output is correct |
25 |
Correct |
24 ms |
2948 KB |
Output is correct |
26 |
Correct |
22 ms |
2420 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
31 ms |
6120 KB |
Output is correct |
36 |
Correct |
110 ms |
11468 KB |
Output is correct |
37 |
Correct |
98 ms |
10872 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
328 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
3 ms |
468 KB |
Output is correct |
46 |
Correct |
4 ms |
600 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
23 ms |
2080 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
4 ms |
472 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
59 ms |
5424 KB |
Output is correct |
56 |
Correct |
31 ms |
3172 KB |
Output is correct |
57 |
Correct |
35 ms |
3256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
52 ms |
5468 KB |
Output is correct |
10 |
Correct |
33 ms |
3788 KB |
Output is correct |
11 |
Correct |
24 ms |
2948 KB |
Output is correct |
12 |
Correct |
22 ms |
2420 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
31 ms |
6120 KB |
Output is correct |
22 |
Correct |
110 ms |
11468 KB |
Output is correct |
23 |
Correct |
98 ms |
10872 KB |
Output is correct |
24 |
Correct |
29 ms |
1892 KB |
Output is correct |
25 |
Correct |
81 ms |
4988 KB |
Output is correct |
26 |
Correct |
15 ms |
1376 KB |
Output is correct |
27 |
Correct |
103 ms |
10820 KB |
Output is correct |
28 |
Correct |
98 ms |
10840 KB |
Output is correct |
29 |
Correct |
101 ms |
10712 KB |
Output is correct |
30 |
Correct |
124 ms |
10812 KB |
Output is correct |
31 |
Correct |
199 ms |
10700 KB |
Output is correct |
32 |
Correct |
127 ms |
6196 KB |
Output is correct |
33 |
Correct |
240 ms |
11468 KB |
Output is correct |
34 |
Correct |
114 ms |
6108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
440 KB |
Output is correct |
11 |
Correct |
118 ms |
10816 KB |
Output is correct |
12 |
Correct |
119 ms |
10812 KB |
Output is correct |
13 |
Correct |
85 ms |
8780 KB |
Output is correct |
14 |
Correct |
95 ms |
8752 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
52 ms |
5468 KB |
Output is correct |
24 |
Correct |
33 ms |
3788 KB |
Output is correct |
25 |
Correct |
24 ms |
2948 KB |
Output is correct |
26 |
Correct |
22 ms |
2420 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
328 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
3 ms |
468 KB |
Output is correct |
42 |
Correct |
4 ms |
600 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
23 ms |
2080 KB |
Output is correct |
45 |
Correct |
1 ms |
344 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
4 ms |
472 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
59 ms |
5424 KB |
Output is correct |
52 |
Correct |
31 ms |
3172 KB |
Output is correct |
53 |
Correct |
35 ms |
3256 KB |
Output is correct |
54 |
Correct |
29 ms |
1892 KB |
Output is correct |
55 |
Correct |
81 ms |
4988 KB |
Output is correct |
56 |
Correct |
15 ms |
1376 KB |
Output is correct |
57 |
Correct |
103 ms |
10820 KB |
Output is correct |
58 |
Correct |
98 ms |
10840 KB |
Output is correct |
59 |
Correct |
101 ms |
10712 KB |
Output is correct |
60 |
Correct |
124 ms |
10812 KB |
Output is correct |
61 |
Correct |
199 ms |
10700 KB |
Output is correct |
62 |
Correct |
127 ms |
6196 KB |
Output is correct |
63 |
Correct |
240 ms |
11468 KB |
Output is correct |
64 |
Correct |
114 ms |
6108 KB |
Output is correct |
65 |
Correct |
0 ms |
340 KB |
Output is correct |
66 |
Correct |
31 ms |
6120 KB |
Output is correct |
67 |
Correct |
110 ms |
11468 KB |
Output is correct |
68 |
Correct |
98 ms |
10872 KB |
Output is correct |
69 |
Correct |
25 ms |
1468 KB |
Output is correct |
70 |
Correct |
7 ms |
620 KB |
Output is correct |
71 |
Correct |
1 ms |
260 KB |
Output is correct |
72 |
Correct |
38 ms |
1840 KB |
Output is correct |
73 |
Correct |
8 ms |
620 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
122 ms |
10816 KB |
Output is correct |
76 |
Correct |
143 ms |
10816 KB |
Output is correct |
77 |
Correct |
146 ms |
10748 KB |
Output is correct |
78 |
Correct |
189 ms |
10792 KB |
Output is correct |
79 |
Correct |
247 ms |
10820 KB |
Output is correct |
80 |
Correct |
277 ms |
10812 KB |
Output is correct |
81 |
Correct |
213 ms |
8828 KB |
Output is correct |
82 |
Correct |
297 ms |
8836 KB |
Output is correct |