#include<bits/stdc++.h>
#define F first
#define S second
#define MAX 500005
#define oo 1e18
#define mod 1000000007
#define fast_in ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.setf(ios::fixed);cout.precision(0);
using namespace std;
typedef long long ll;
#define pll pair<ll , ll>
#define vll vector<ll>
#define vvll vector<vll>
#define vpll vector<pll>
ll n,k;
pll a[MAX];
ll OK(ll x){
__int128 m=k*n,r=0;
for(int i=0;i<n;i++){
__int128 moves=min(k,(x+a[i].F-1)/a[i].F);
r+=(max((__int128)0,x-(a[i].F*moves))+a[i].S-1)/a[i].S;
m-=moves;
}
if(r<=m)return 1;
return 0;
}
int main(){
fast_in
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i].F;
}
for(int i=0;i<n;i++){
cin>>a[i].S;a[i].F=max(a[i].S,a[i].F);
}
ll p=0,f=3*oo;
while(abs(p-f)!=1){
ll m=(p+f)/2;
if(OK(m)==1)p=m;
else f=m;
}
cout<<p;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
253 ms |
6772 KB |
Output is correct |
12 |
Correct |
254 ms |
6776 KB |
Output is correct |
13 |
Correct |
243 ms |
6788 KB |
Output is correct |
14 |
Correct |
292 ms |
6748 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
354 ms |
7800 KB |
Output is correct |
17 |
Correct |
257 ms |
13220 KB |
Output is correct |
18 |
Correct |
256 ms |
12568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
354 ms |
7800 KB |
Output is correct |
3 |
Correct |
257 ms |
13220 KB |
Output is correct |
4 |
Correct |
256 ms |
12568 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 |
0 ms |
348 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 |
129 ms |
4744 KB |
Output is correct |
14 |
Correct |
88 ms |
2672 KB |
Output is correct |
15 |
Correct |
69 ms |
2652 KB |
Output is correct |
16 |
Correct |
53 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
6 ms |
344 KB |
Output is correct |
23 |
Correct |
5 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
253 ms |
6772 KB |
Output is correct |
12 |
Correct |
254 ms |
6776 KB |
Output is correct |
13 |
Correct |
243 ms |
6788 KB |
Output is correct |
14 |
Correct |
292 ms |
6748 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
129 ms |
4744 KB |
Output is correct |
24 |
Correct |
88 ms |
2672 KB |
Output is correct |
25 |
Correct |
69 ms |
2652 KB |
Output is correct |
26 |
Correct |
53 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
6 ms |
344 KB |
Output is correct |
33 |
Correct |
5 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
354 ms |
7800 KB |
Output is correct |
36 |
Correct |
257 ms |
13220 KB |
Output is correct |
37 |
Correct |
256 ms |
12568 KB |
Output is correct |
38 |
Correct |
0 ms |
600 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
5 ms |
604 KB |
Output is correct |
46 |
Correct |
8 ms |
600 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
46 ms |
3660 KB |
Output is correct |
49 |
Correct |
1 ms |
492 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
5 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 |
128 ms |
7412 KB |
Output is correct |
56 |
Correct |
81 ms |
3940 KB |
Output is correct |
57 |
Correct |
98 ms |
3960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
129 ms |
4744 KB |
Output is correct |
10 |
Correct |
88 ms |
2672 KB |
Output is correct |
11 |
Correct |
69 ms |
2652 KB |
Output is correct |
12 |
Correct |
53 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
6 ms |
344 KB |
Output is correct |
19 |
Correct |
5 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
354 ms |
7800 KB |
Output is correct |
22 |
Correct |
257 ms |
13220 KB |
Output is correct |
23 |
Correct |
256 ms |
12568 KB |
Output is correct |
24 |
Correct |
49 ms |
3564 KB |
Output is correct |
25 |
Correct |
129 ms |
5268 KB |
Output is correct |
26 |
Correct |
29 ms |
3164 KB |
Output is correct |
27 |
Correct |
260 ms |
12372 KB |
Output is correct |
28 |
Correct |
264 ms |
12572 KB |
Output is correct |
29 |
Correct |
269 ms |
12568 KB |
Output is correct |
30 |
Correct |
272 ms |
12628 KB |
Output is correct |
31 |
Correct |
290 ms |
12572 KB |
Output is correct |
32 |
Correct |
371 ms |
7948 KB |
Output is correct |
33 |
Correct |
310 ms |
13224 KB |
Output is correct |
34 |
Correct |
366 ms |
7948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
253 ms |
6772 KB |
Output is correct |
12 |
Correct |
254 ms |
6776 KB |
Output is correct |
13 |
Correct |
243 ms |
6788 KB |
Output is correct |
14 |
Correct |
292 ms |
6748 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
129 ms |
4744 KB |
Output is correct |
24 |
Correct |
88 ms |
2672 KB |
Output is correct |
25 |
Correct |
69 ms |
2652 KB |
Output is correct |
26 |
Correct |
53 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
6 ms |
344 KB |
Output is correct |
33 |
Correct |
5 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
600 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
5 ms |
604 KB |
Output is correct |
42 |
Correct |
8 ms |
600 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
46 ms |
3660 KB |
Output is correct |
45 |
Correct |
1 ms |
492 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
5 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 |
128 ms |
7412 KB |
Output is correct |
52 |
Correct |
81 ms |
3940 KB |
Output is correct |
53 |
Correct |
98 ms |
3960 KB |
Output is correct |
54 |
Correct |
49 ms |
3564 KB |
Output is correct |
55 |
Correct |
129 ms |
5268 KB |
Output is correct |
56 |
Correct |
29 ms |
3164 KB |
Output is correct |
57 |
Correct |
260 ms |
12372 KB |
Output is correct |
58 |
Correct |
264 ms |
12572 KB |
Output is correct |
59 |
Correct |
269 ms |
12568 KB |
Output is correct |
60 |
Correct |
272 ms |
12628 KB |
Output is correct |
61 |
Correct |
290 ms |
12572 KB |
Output is correct |
62 |
Correct |
371 ms |
7948 KB |
Output is correct |
63 |
Correct |
310 ms |
13224 KB |
Output is correct |
64 |
Correct |
366 ms |
7948 KB |
Output is correct |
65 |
Correct |
1 ms |
348 KB |
Output is correct |
66 |
Correct |
354 ms |
7800 KB |
Output is correct |
67 |
Correct |
257 ms |
13220 KB |
Output is correct |
68 |
Correct |
256 ms |
12568 KB |
Output is correct |
69 |
Correct |
33 ms |
3164 KB |
Output is correct |
70 |
Correct |
9 ms |
604 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
44 ms |
3420 KB |
Output is correct |
73 |
Correct |
10 ms |
604 KB |
Output is correct |
74 |
Correct |
1 ms |
348 KB |
Output is correct |
75 |
Correct |
263 ms |
12568 KB |
Output is correct |
76 |
Correct |
270 ms |
12580 KB |
Output is correct |
77 |
Correct |
278 ms |
12372 KB |
Output is correct |
78 |
Correct |
290 ms |
12680 KB |
Output is correct |
79 |
Correct |
310 ms |
12576 KB |
Output is correct |
80 |
Correct |
303 ms |
12784 KB |
Output is correct |
81 |
Correct |
290 ms |
10576 KB |
Output is correct |
82 |
Correct |
320 ms |
10588 KB |
Output is correct |