#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define INF (ll)(9e18)
#define int LL
using namespace std;
using LL=long long;
using pii=pair<int,int>;
const int MAXN=300030;
int a[MAXN];
int b[MAXN];
bool check(__int128_t n,__int128_t m,__int128_t tar){
__int128_t s=0,d=0;
For(i,1,n){
__int128_t t=tar;
__int128_t r=min(m,(t+a[i]-1)/a[i]);
t-=r*a[i];
if(t>0){
d+=(t+b[i]-1)/b[i];
}else{
s+=m-r;
}
}
return s>=d;
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0);
// OAO
int n,m; cin>>n>>m;
For(i,1,n) cin>>a[i];
For(i,1,n){
cin>>b[i];
a[i]=max(a[i],b[i]);
}
int hi=1000000000000000010;
int lo=0;
while(hi-lo>1){
int mi=(hi+lo)/2;
if(check(n,m,mi)) lo=mi;
else hi=mi;
}
cout<<lo<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
269 ms |
4988 KB |
Output is correct |
12 |
Correct |
275 ms |
4992 KB |
Output is correct |
13 |
Correct |
263 ms |
4992 KB |
Output is correct |
14 |
Correct |
330 ms |
5000 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
374 ms |
4988 KB |
Output is correct |
17 |
Correct |
287 ms |
5060 KB |
Output is correct |
18 |
Correct |
231 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
374 ms |
4988 KB |
Output is correct |
3 |
Correct |
287 ms |
5060 KB |
Output is correct |
4 |
Correct |
231 ms |
4944 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 |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
137 ms |
2656 KB |
Output is correct |
14 |
Correct |
92 ms |
1868 KB |
Output is correct |
15 |
Correct |
66 ms |
1476 KB |
Output is correct |
16 |
Correct |
49 ms |
1172 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 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 |
7 ms |
400 KB |
Output is correct |
23 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
269 ms |
4988 KB |
Output is correct |
12 |
Correct |
275 ms |
4992 KB |
Output is correct |
13 |
Correct |
263 ms |
4992 KB |
Output is correct |
14 |
Correct |
330 ms |
5000 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
137 ms |
2656 KB |
Output is correct |
24 |
Correct |
92 ms |
1868 KB |
Output is correct |
25 |
Correct |
66 ms |
1476 KB |
Output is correct |
26 |
Correct |
49 ms |
1172 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
7 ms |
400 KB |
Output is correct |
33 |
Correct |
5 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
374 ms |
4988 KB |
Output is correct |
36 |
Correct |
287 ms |
5060 KB |
Output is correct |
37 |
Correct |
231 ms |
4944 KB |
Output is correct |
38 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
1 ms |
204 KB |
Output is correct |
45 |
Correct |
5 ms |
332 KB |
Output is correct |
46 |
Correct |
8 ms |
464 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
45 ms |
1036 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
5 ms |
400 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 |
138 ms |
2636 KB |
Output is correct |
56 |
Correct |
83 ms |
1868 KB |
Output is correct |
57 |
Correct |
118 ms |
1868 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 |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
137 ms |
2656 KB |
Output is correct |
10 |
Correct |
92 ms |
1868 KB |
Output is correct |
11 |
Correct |
66 ms |
1476 KB |
Output is correct |
12 |
Correct |
49 ms |
1172 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
7 ms |
400 KB |
Output is correct |
19 |
Correct |
5 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
374 ms |
4988 KB |
Output is correct |
22 |
Correct |
287 ms |
5060 KB |
Output is correct |
23 |
Correct |
231 ms |
4944 KB |
Output is correct |
24 |
Correct |
43 ms |
944 KB |
Output is correct |
25 |
Correct |
118 ms |
2408 KB |
Output is correct |
26 |
Correct |
27 ms |
716 KB |
Output is correct |
27 |
Correct |
260 ms |
5092 KB |
Output is correct |
28 |
Correct |
250 ms |
4956 KB |
Output is correct |
29 |
Correct |
254 ms |
4988 KB |
Output is correct |
30 |
Correct |
249 ms |
4992 KB |
Output is correct |
31 |
Correct |
249 ms |
4932 KB |
Output is correct |
32 |
Correct |
367 ms |
4988 KB |
Output is correct |
33 |
Correct |
300 ms |
4948 KB |
Output is correct |
34 |
Correct |
390 ms |
4992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
269 ms |
4988 KB |
Output is correct |
12 |
Correct |
275 ms |
4992 KB |
Output is correct |
13 |
Correct |
263 ms |
4992 KB |
Output is correct |
14 |
Correct |
330 ms |
5000 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
137 ms |
2656 KB |
Output is correct |
24 |
Correct |
92 ms |
1868 KB |
Output is correct |
25 |
Correct |
66 ms |
1476 KB |
Output is correct |
26 |
Correct |
49 ms |
1172 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
7 ms |
400 KB |
Output is correct |
33 |
Correct |
5 ms |
332 KB |
Output is correct |
34 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
5 ms |
332 KB |
Output is correct |
42 |
Correct |
8 ms |
464 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
45 ms |
1036 KB |
Output is correct |
45 |
Correct |
0 ms |
204 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
5 ms |
400 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 |
138 ms |
2636 KB |
Output is correct |
52 |
Correct |
83 ms |
1868 KB |
Output is correct |
53 |
Correct |
118 ms |
1868 KB |
Output is correct |
54 |
Correct |
43 ms |
944 KB |
Output is correct |
55 |
Correct |
118 ms |
2408 KB |
Output is correct |
56 |
Correct |
27 ms |
716 KB |
Output is correct |
57 |
Correct |
260 ms |
5092 KB |
Output is correct |
58 |
Correct |
250 ms |
4956 KB |
Output is correct |
59 |
Correct |
254 ms |
4988 KB |
Output is correct |
60 |
Correct |
249 ms |
4992 KB |
Output is correct |
61 |
Correct |
249 ms |
4932 KB |
Output is correct |
62 |
Correct |
367 ms |
4988 KB |
Output is correct |
63 |
Correct |
300 ms |
4948 KB |
Output is correct |
64 |
Correct |
390 ms |
4992 KB |
Output is correct |
65 |
Correct |
0 ms |
204 KB |
Output is correct |
66 |
Correct |
374 ms |
4988 KB |
Output is correct |
67 |
Correct |
287 ms |
5060 KB |
Output is correct |
68 |
Correct |
231 ms |
4944 KB |
Output is correct |
69 |
Correct |
33 ms |
816 KB |
Output is correct |
70 |
Correct |
8 ms |
444 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Correct |
40 ms |
984 KB |
Output is correct |
73 |
Correct |
9 ms |
452 KB |
Output is correct |
74 |
Correct |
1 ms |
332 KB |
Output is correct |
75 |
Correct |
246 ms |
5060 KB |
Output is correct |
76 |
Correct |
282 ms |
5144 KB |
Output is correct |
77 |
Correct |
242 ms |
5068 KB |
Output is correct |
78 |
Correct |
292 ms |
5036 KB |
Output is correct |
79 |
Correct |
269 ms |
5060 KB |
Output is correct |
80 |
Correct |
274 ms |
4980 KB |
Output is correct |
81 |
Correct |
229 ms |
5104 KB |
Output is correct |
82 |
Correct |
229 ms |
4972 KB |
Output is correct |