#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
constexpr int INF = (int)2e9;
constexpr int N = (int)4e5 + 111;
constexpr int md = (int)1e9+7;
constexpr int mdPower = (int)1e9+7 - 1;
constexpr double eps = 1e-7;
typedef __int128 _uint;
typedef long long ll;
mt19937_64 rnd(time(nullptr));
void add(int& a,int b){
a += b; if(a >= md) a -= md;
}
void sub(int& a,int b){
a -= b; while(a < 0) a += md;
}
void add(__int128& a,int b){
a += b;
}
void sub(__int128& a,int b){
a -= b;
}
int bpow(int a,int b){
if(b == 0)
return 1;
if(b % 2 == 0){
int t = bpow(a,b>>1);
return 1ll*t*t%md;
}
return 1ll * a*bpow(a,b-1) % md;
}
int inv(int a){
return bpow(a,md-2);
}
//int fac[N],invfac[N];
//
//void init(){
// fac[0] = 1;
// for(int i = 1; i < N; i++){
// fac[i] = (fac[i-1] * i) % md;
// }
// invfac[N-1] = inv(fac[N-1]);
// for(int i = N-2; i >= 0; i--){
// invfac[i] = (invfac[i+1] * (i+1))%md;
// }
// return;
//}
//
//int C(int n,int k){
// if(k > n)
// return 0;
// return fac[n] * invfac[k] % md * invfac[n-k] % md;
//}
//
//int A(int n,int k){
// if(k > n)
// return 0;
// return fac[n] * invfac[n-k] % md;
//
int n,m;
int a[N],b[N];
int cur[N];
bool f(int x){
int free = n*m;
for(int i = 0; i < n; i++){
cur[i] = 0;
}
for(int i = 0; i < n; i++){
if(a[i] > b[i]){
int t = min(m,(x + a[i] - 1)/a[i]);
free -= t;
cur[i] += t * a[i];
}
}
for(int i = 0; i < n; i++){
if(cur[i] >= x)
continue;
int t = min(free,((x-cur[i]) + b[i] - 1) / b[i]);
free -= t;
cur[i] += t * b[i];
if(cur[i] < x)
return false;
}
return true;
}
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];
}
int l = 0, r = (int)2e18;
while(r - l > 1){
int mid = (l+r)>>1;
if(f(mid))
l = mid;
else
r = mid;
}
cout << l << "\n";
return;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int tests = 1;
// cin >> tests;
for(int test = 1; test <= tests; test++){
// cerr << "test = " << test << "\n";
solve();
}
return 0;
}
/**
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
412 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
484 KB |
Output is correct |
11 |
Correct |
210 ms |
13180 KB |
Output is correct |
12 |
Correct |
197 ms |
13116 KB |
Output is correct |
13 |
Correct |
102 ms |
11116 KB |
Output is correct |
14 |
Correct |
167 ms |
11204 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
58 ms |
8544 KB |
Output is correct |
17 |
Correct |
124 ms |
13796 KB |
Output is correct |
18 |
Correct |
115 ms |
13108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
58 ms |
8544 KB |
Output is correct |
3 |
Correct |
124 ms |
13796 KB |
Output is correct |
4 |
Correct |
115 ms |
13108 KB |
Output is correct |
5 |
Correct |
1 ms |
476 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
60 ms |
6680 KB |
Output is correct |
14 |
Correct |
38 ms |
4584 KB |
Output is correct |
15 |
Correct |
29 ms |
3548 KB |
Output is correct |
16 |
Correct |
25 ms |
2888 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 |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
476 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
412 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
484 KB |
Output is correct |
11 |
Correct |
210 ms |
13180 KB |
Output is correct |
12 |
Correct |
197 ms |
13116 KB |
Output is correct |
13 |
Correct |
102 ms |
11116 KB |
Output is correct |
14 |
Correct |
167 ms |
11204 KB |
Output is correct |
15 |
Correct |
1 ms |
476 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
60 ms |
6680 KB |
Output is correct |
24 |
Correct |
38 ms |
4584 KB |
Output is correct |
25 |
Correct |
29 ms |
3548 KB |
Output is correct |
26 |
Correct |
25 ms |
2888 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 |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
476 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
58 ms |
8544 KB |
Output is correct |
36 |
Correct |
124 ms |
13796 KB |
Output is correct |
37 |
Correct |
115 ms |
13108 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
336 KB |
Output is correct |
45 |
Correct |
3 ms |
468 KB |
Output is correct |
46 |
Correct |
5 ms |
736 KB |
Output is correct |
47 |
Correct |
1 ms |
344 KB |
Output is correct |
48 |
Correct |
31 ms |
2428 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
3 ms |
472 KB |
Output is correct |
52 |
Correct |
0 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
101 ms |
6620 KB |
Output is correct |
56 |
Correct |
38 ms |
3920 KB |
Output is correct |
57 |
Correct |
61 ms |
3836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
476 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
60 ms |
6680 KB |
Output is correct |
10 |
Correct |
38 ms |
4584 KB |
Output is correct |
11 |
Correct |
29 ms |
3548 KB |
Output is correct |
12 |
Correct |
25 ms |
2888 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 |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
476 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
58 ms |
8544 KB |
Output is correct |
22 |
Correct |
124 ms |
13796 KB |
Output is correct |
23 |
Correct |
115 ms |
13108 KB |
Output is correct |
24 |
Correct |
35 ms |
2316 KB |
Output is correct |
25 |
Correct |
92 ms |
6088 KB |
Output is correct |
26 |
Correct |
14 ms |
1620 KB |
Output is correct |
27 |
Correct |
114 ms |
13180 KB |
Output is correct |
28 |
Correct |
122 ms |
13180 KB |
Output is correct |
29 |
Correct |
131 ms |
13068 KB |
Output is correct |
30 |
Correct |
145 ms |
13260 KB |
Output is correct |
31 |
Correct |
234 ms |
13180 KB |
Output is correct |
32 |
Correct |
137 ms |
8544 KB |
Output is correct |
33 |
Correct |
270 ms |
13880 KB |
Output is correct |
34 |
Correct |
134 ms |
8448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
412 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
484 KB |
Output is correct |
11 |
Correct |
210 ms |
13180 KB |
Output is correct |
12 |
Correct |
197 ms |
13116 KB |
Output is correct |
13 |
Correct |
102 ms |
11116 KB |
Output is correct |
14 |
Correct |
167 ms |
11204 KB |
Output is correct |
15 |
Correct |
1 ms |
476 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
60 ms |
6680 KB |
Output is correct |
24 |
Correct |
38 ms |
4584 KB |
Output is correct |
25 |
Correct |
29 ms |
3548 KB |
Output is correct |
26 |
Correct |
25 ms |
2888 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 |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
476 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
336 KB |
Output is correct |
41 |
Correct |
3 ms |
468 KB |
Output is correct |
42 |
Correct |
5 ms |
736 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
31 ms |
2428 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
3 ms |
472 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
101 ms |
6620 KB |
Output is correct |
52 |
Correct |
38 ms |
3920 KB |
Output is correct |
53 |
Correct |
61 ms |
3836 KB |
Output is correct |
54 |
Correct |
35 ms |
2316 KB |
Output is correct |
55 |
Correct |
92 ms |
6088 KB |
Output is correct |
56 |
Correct |
14 ms |
1620 KB |
Output is correct |
57 |
Correct |
114 ms |
13180 KB |
Output is correct |
58 |
Correct |
122 ms |
13180 KB |
Output is correct |
59 |
Correct |
131 ms |
13068 KB |
Output is correct |
60 |
Correct |
145 ms |
13260 KB |
Output is correct |
61 |
Correct |
234 ms |
13180 KB |
Output is correct |
62 |
Correct |
137 ms |
8544 KB |
Output is correct |
63 |
Correct |
270 ms |
13880 KB |
Output is correct |
64 |
Correct |
134 ms |
8448 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
58 ms |
8544 KB |
Output is correct |
67 |
Correct |
124 ms |
13796 KB |
Output is correct |
68 |
Correct |
115 ms |
13108 KB |
Output is correct |
69 |
Correct |
24 ms |
1716 KB |
Output is correct |
70 |
Correct |
6 ms |
596 KB |
Output is correct |
71 |
Correct |
0 ms |
340 KB |
Output is correct |
72 |
Correct |
34 ms |
2180 KB |
Output is correct |
73 |
Correct |
7 ms |
728 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
211 ms |
13180 KB |
Output is correct |
76 |
Correct |
207 ms |
13216 KB |
Output is correct |
77 |
Correct |
220 ms |
13132 KB |
Output is correct |
78 |
Correct |
238 ms |
13180 KB |
Output is correct |
79 |
Correct |
251 ms |
13168 KB |
Output is correct |
80 |
Correct |
261 ms |
13288 KB |
Output is correct |
81 |
Correct |
245 ms |
11188 KB |
Output is correct |
82 |
Correct |
230 ms |
11192 KB |
Output is correct |