#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=3e5;
int a[N+10];
int b[N+10];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>b[i];
long long bg=1,en=1e18L+7;
while(bg<en)
{
long long mid=(bg+en+1)/2;
long long cnt=0;
for(int i=1;i<=n;i++)
{
long long x=mid;
if(a[i]>b[i])
{
long long k=(x+a[i]-1)/a[i];
k=min(k,(long long)m);
x-=k*a[i];
cnt+=k;
}
if(x>0)
cnt+=(x+b[i]-1)/b[i];
if(cnt>(long long)n*m)
break;
}
if(cnt<=(long long)n*m)
bg=mid;
else
en=mid-1;
}
cout<<bg<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
324 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
112 ms |
7328 KB |
Output is correct |
12 |
Correct |
108 ms |
7016 KB |
Output is correct |
13 |
Correct |
84 ms |
4156 KB |
Output is correct |
14 |
Correct |
77 ms |
6468 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
29 ms |
2872 KB |
Output is correct |
17 |
Correct |
102 ms |
3404 KB |
Output is correct |
18 |
Correct |
94 ms |
3748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
29 ms |
2872 KB |
Output is correct |
3 |
Correct |
102 ms |
3404 KB |
Output is correct |
4 |
Correct |
94 ms |
3748 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
52 ms |
3520 KB |
Output is correct |
14 |
Correct |
35 ms |
1892 KB |
Output is correct |
15 |
Correct |
25 ms |
1416 KB |
Output is correct |
16 |
Correct |
22 ms |
1348 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
3 ms |
480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
324 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
112 ms |
7328 KB |
Output is correct |
12 |
Correct |
108 ms |
7016 KB |
Output is correct |
13 |
Correct |
84 ms |
4156 KB |
Output is correct |
14 |
Correct |
77 ms |
6468 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
316 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 |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
52 ms |
3520 KB |
Output is correct |
24 |
Correct |
35 ms |
1892 KB |
Output is correct |
25 |
Correct |
25 ms |
1416 KB |
Output is correct |
26 |
Correct |
22 ms |
1348 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
3 ms |
480 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
29 ms |
2872 KB |
Output is correct |
36 |
Correct |
102 ms |
3404 KB |
Output is correct |
37 |
Correct |
94 ms |
3748 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
320 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
0 ms |
204 KB |
Output is correct |
45 |
Correct |
3 ms |
324 KB |
Output is correct |
46 |
Correct |
4 ms |
396 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
19 ms |
1256 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
3 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
204 KB |
Output is correct |
53 |
Correct |
1 ms |
204 KB |
Output is correct |
54 |
Correct |
1 ms |
320 KB |
Output is correct |
55 |
Correct |
57 ms |
3140 KB |
Output is correct |
56 |
Correct |
32 ms |
1580 KB |
Output is correct |
57 |
Correct |
27 ms |
1732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
52 ms |
3520 KB |
Output is correct |
10 |
Correct |
35 ms |
1892 KB |
Output is correct |
11 |
Correct |
25 ms |
1416 KB |
Output is correct |
12 |
Correct |
22 ms |
1348 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
480 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
29 ms |
2872 KB |
Output is correct |
22 |
Correct |
102 ms |
3404 KB |
Output is correct |
23 |
Correct |
94 ms |
3748 KB |
Output is correct |
24 |
Correct |
31 ms |
964 KB |
Output is correct |
25 |
Correct |
69 ms |
2164 KB |
Output is correct |
26 |
Correct |
14 ms |
708 KB |
Output is correct |
27 |
Correct |
92 ms |
4392 KB |
Output is correct |
28 |
Correct |
97 ms |
4288 KB |
Output is correct |
29 |
Correct |
100 ms |
4260 KB |
Output is correct |
30 |
Correct |
122 ms |
4516 KB |
Output is correct |
31 |
Correct |
195 ms |
5572 KB |
Output is correct |
32 |
Correct |
115 ms |
3248 KB |
Output is correct |
33 |
Correct |
245 ms |
4304 KB |
Output is correct |
34 |
Correct |
109 ms |
2712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
324 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
112 ms |
7328 KB |
Output is correct |
12 |
Correct |
108 ms |
7016 KB |
Output is correct |
13 |
Correct |
84 ms |
4156 KB |
Output is correct |
14 |
Correct |
77 ms |
6468 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
316 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 |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
52 ms |
3520 KB |
Output is correct |
24 |
Correct |
35 ms |
1892 KB |
Output is correct |
25 |
Correct |
25 ms |
1416 KB |
Output is correct |
26 |
Correct |
22 ms |
1348 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
3 ms |
480 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
320 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
332 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 |
3 ms |
324 KB |
Output is correct |
42 |
Correct |
4 ms |
396 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
19 ms |
1256 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
3 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
1 ms |
204 KB |
Output is correct |
50 |
Correct |
1 ms |
320 KB |
Output is correct |
51 |
Correct |
57 ms |
3140 KB |
Output is correct |
52 |
Correct |
32 ms |
1580 KB |
Output is correct |
53 |
Correct |
27 ms |
1732 KB |
Output is correct |
54 |
Correct |
31 ms |
964 KB |
Output is correct |
55 |
Correct |
69 ms |
2164 KB |
Output is correct |
56 |
Correct |
14 ms |
708 KB |
Output is correct |
57 |
Correct |
92 ms |
4392 KB |
Output is correct |
58 |
Correct |
97 ms |
4288 KB |
Output is correct |
59 |
Correct |
100 ms |
4260 KB |
Output is correct |
60 |
Correct |
122 ms |
4516 KB |
Output is correct |
61 |
Correct |
195 ms |
5572 KB |
Output is correct |
62 |
Correct |
115 ms |
3248 KB |
Output is correct |
63 |
Correct |
245 ms |
4304 KB |
Output is correct |
64 |
Correct |
109 ms |
2712 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
29 ms |
2872 KB |
Output is correct |
67 |
Correct |
102 ms |
3404 KB |
Output is correct |
68 |
Correct |
94 ms |
3748 KB |
Output is correct |
69 |
Correct |
22 ms |
652 KB |
Output is correct |
70 |
Correct |
6 ms |
332 KB |
Output is correct |
71 |
Correct |
0 ms |
208 KB |
Output is correct |
72 |
Correct |
32 ms |
916 KB |
Output is correct |
73 |
Correct |
8 ms |
460 KB |
Output is correct |
74 |
Correct |
1 ms |
332 KB |
Output is correct |
75 |
Correct |
116 ms |
4548 KB |
Output is correct |
76 |
Correct |
124 ms |
4420 KB |
Output is correct |
77 |
Correct |
132 ms |
3872 KB |
Output is correct |
78 |
Correct |
163 ms |
2976 KB |
Output is correct |
79 |
Correct |
217 ms |
4508 KB |
Output is correct |
80 |
Correct |
225 ms |
7244 KB |
Output is correct |
81 |
Correct |
219 ms |
4164 KB |
Output is correct |
82 |
Correct |
222 ms |
4548 KB |
Output is correct |