#include<bits/stdc++.h>
using namespace std;
long long int N,M,Count,Total_time,tmp;
vector<long long int> List;
vector<long long int> List_2;
int check(long long int x){
//cout<<x<<"\n";
long long int Free = 0, Ask = 0;
for(int i=0;i<(int)List.size();i++){
if(List[i]<List_2[i]){
Free += M;
if(!(x%List_2[i])) Ask += x/List_2[i];
else Ask += x/List_2[i]+1;
if(Ask < 0) return 0;
}
else{
long long int Add=0
;
if(!(x%List[i])) Add = x/List[i];
else Add += x/List[i]+1;
if(Add<=M){
Free += M-Add;
}
else{
if(!((x-List[i]*M)%List_2[i])) Ask += (x-List[i]*M)/List_2[i];
else Ask += (x-List[i]*M)/List_2[i]+1;
}
if(Ask < 0) return 0;
}
}
if(Ask>Free) return 0;
else return 1;
/*
cout<<x<<" ";
int Back;
cin>>Back;
return Back;
*/
}
int main(){
cin>>N>>M;
for(int i=1;i<=N;i++){
cin>>tmp;
List.push_back(tmp);
}
for(int i=1;i<=N;i++){
cin>>tmp;
List_2.push_back(tmp);
}
Total_time=N*M;
long long int L = 0,R = 2000000000000000003;
while(L!=R){
long long int M = (L+R)/2+1;
if(check(M)) L=M;
else R=M-1;
}
cout<<L;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
296 KB |
Output is correct |
10 |
Correct |
7 ms |
468 KB |
Output is correct |
11 |
Correct |
358 ms |
14340 KB |
Output is correct |
12 |
Correct |
369 ms |
14384 KB |
Output is correct |
13 |
Correct |
258 ms |
12304 KB |
Output is correct |
14 |
Correct |
308 ms |
12560 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
314 ms |
9188 KB |
Output is correct |
17 |
Correct |
415 ms |
9260 KB |
Output is correct |
18 |
Correct |
400 ms |
9136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
314 ms |
9188 KB |
Output is correct |
3 |
Correct |
415 ms |
9260 KB |
Output is correct |
4 |
Correct |
400 ms |
9136 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
213 ms |
5308 KB |
Output is correct |
14 |
Correct |
135 ms |
3432 KB |
Output is correct |
15 |
Correct |
99 ms |
3264 KB |
Output is correct |
16 |
Correct |
86 ms |
2360 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
6 ms |
340 KB |
Output is correct |
23 |
Correct |
8 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
296 KB |
Output is correct |
10 |
Correct |
7 ms |
468 KB |
Output is correct |
11 |
Correct |
358 ms |
14340 KB |
Output is correct |
12 |
Correct |
369 ms |
14384 KB |
Output is correct |
13 |
Correct |
258 ms |
12304 KB |
Output is correct |
14 |
Correct |
308 ms |
12560 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
296 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
213 ms |
5308 KB |
Output is correct |
24 |
Correct |
135 ms |
3432 KB |
Output is correct |
25 |
Correct |
99 ms |
3264 KB |
Output is correct |
26 |
Correct |
86 ms |
2360 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
8 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
296 KB |
Output is correct |
35 |
Correct |
314 ms |
9188 KB |
Output is correct |
36 |
Correct |
415 ms |
9260 KB |
Output is correct |
37 |
Correct |
400 ms |
9136 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
296 KB |
Output is correct |
45 |
Correct |
7 ms |
520 KB |
Output is correct |
46 |
Correct |
12 ms |
724 KB |
Output is correct |
47 |
Correct |
2 ms |
252 KB |
Output is correct |
48 |
Correct |
64 ms |
2344 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
7 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
304 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
179 ms |
7308 KB |
Output is correct |
56 |
Correct |
89 ms |
3704 KB |
Output is correct |
57 |
Correct |
115 ms |
3764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
213 ms |
5308 KB |
Output is correct |
10 |
Correct |
135 ms |
3432 KB |
Output is correct |
11 |
Correct |
99 ms |
3264 KB |
Output is correct |
12 |
Correct |
86 ms |
2360 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
6 ms |
340 KB |
Output is correct |
19 |
Correct |
8 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
296 KB |
Output is correct |
21 |
Correct |
314 ms |
9188 KB |
Output is correct |
22 |
Correct |
415 ms |
9260 KB |
Output is correct |
23 |
Correct |
400 ms |
9136 KB |
Output is correct |
24 |
Correct |
65 ms |
1908 KB |
Output is correct |
25 |
Correct |
186 ms |
4716 KB |
Output is correct |
26 |
Correct |
48 ms |
1276 KB |
Output is correct |
27 |
Correct |
396 ms |
9108 KB |
Output is correct |
28 |
Correct |
392 ms |
9172 KB |
Output is correct |
29 |
Correct |
390 ms |
9132 KB |
Output is correct |
30 |
Correct |
402 ms |
9164 KB |
Output is correct |
31 |
Correct |
385 ms |
9200 KB |
Output is correct |
32 |
Correct |
313 ms |
9136 KB |
Output is correct |
33 |
Correct |
398 ms |
9144 KB |
Output is correct |
34 |
Correct |
313 ms |
9136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
296 KB |
Output is correct |
10 |
Correct |
7 ms |
468 KB |
Output is correct |
11 |
Correct |
358 ms |
14340 KB |
Output is correct |
12 |
Correct |
369 ms |
14384 KB |
Output is correct |
13 |
Correct |
258 ms |
12304 KB |
Output is correct |
14 |
Correct |
308 ms |
12560 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
296 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
213 ms |
5308 KB |
Output is correct |
24 |
Correct |
135 ms |
3432 KB |
Output is correct |
25 |
Correct |
99 ms |
3264 KB |
Output is correct |
26 |
Correct |
86 ms |
2360 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
8 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
296 KB |
Output is correct |
41 |
Correct |
7 ms |
520 KB |
Output is correct |
42 |
Correct |
12 ms |
724 KB |
Output is correct |
43 |
Correct |
2 ms |
252 KB |
Output is correct |
44 |
Correct |
64 ms |
2344 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
7 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
304 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
179 ms |
7308 KB |
Output is correct |
52 |
Correct |
89 ms |
3704 KB |
Output is correct |
53 |
Correct |
115 ms |
3764 KB |
Output is correct |
54 |
Correct |
65 ms |
1908 KB |
Output is correct |
55 |
Correct |
186 ms |
4716 KB |
Output is correct |
56 |
Correct |
48 ms |
1276 KB |
Output is correct |
57 |
Correct |
396 ms |
9108 KB |
Output is correct |
58 |
Correct |
392 ms |
9172 KB |
Output is correct |
59 |
Correct |
390 ms |
9132 KB |
Output is correct |
60 |
Correct |
402 ms |
9164 KB |
Output is correct |
61 |
Correct |
385 ms |
9200 KB |
Output is correct |
62 |
Correct |
313 ms |
9136 KB |
Output is correct |
63 |
Correct |
398 ms |
9144 KB |
Output is correct |
64 |
Correct |
313 ms |
9136 KB |
Output is correct |
65 |
Correct |
1 ms |
296 KB |
Output is correct |
66 |
Correct |
314 ms |
9188 KB |
Output is correct |
67 |
Correct |
415 ms |
9260 KB |
Output is correct |
68 |
Correct |
400 ms |
9136 KB |
Output is correct |
69 |
Correct |
42 ms |
1540 KB |
Output is correct |
70 |
Correct |
11 ms |
596 KB |
Output is correct |
71 |
Correct |
1 ms |
300 KB |
Output is correct |
72 |
Correct |
59 ms |
2152 KB |
Output is correct |
73 |
Correct |
13 ms |
720 KB |
Output is correct |
74 |
Correct |
2 ms |
340 KB |
Output is correct |
75 |
Correct |
373 ms |
14420 KB |
Output is correct |
76 |
Correct |
377 ms |
14384 KB |
Output is correct |
77 |
Correct |
405 ms |
14356 KB |
Output is correct |
78 |
Correct |
382 ms |
14356 KB |
Output is correct |
79 |
Correct |
442 ms |
14332 KB |
Output is correct |
80 |
Correct |
395 ms |
14504 KB |
Output is correct |
81 |
Correct |
329 ms |
12364 KB |
Output is correct |
82 |
Correct |
339 ms |
12504 KB |
Output is correct |