#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 3*1e5;
int n, m, A[MAX_N], B[MAX_N], C[MAX_N];
bool check(int target){
//cout<<"target "<<target<<endl;
for(int i = 0; i<n; i++){
C[i] = A[i] * m;
}
int excess= 0;
for(int i = 0; i<n; i++){
if(C[i]>target){
excess += (C[i]-target)/A[i];
C[i]-= ((C[i]-target)/A[i])*A[i];
}
}
for(int i = 0; i<n; i++){
if(C[i]<target){
int need = (target-C[i]+B[i]-1)/B[i];
if(excess>=need){
excess-=need;
}
else{
return false;
}
}
}
return true;
}
signed main(){
cin>>n>>m;
for(int i = 0; i<n; i++){
cin>>A[i];
}
for(int i = 0; i<n; i++){
cin>>B[i];
A[i] = max(A[i], B[i]);
}
int res= 0LL;
for(int step = (1LL<<61LL); step>=1LL; step/=2LL){
//cout<<"hello "<<step<<endl;
if(check(res+step)){
res+=step;
}
}
cout<<res<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
444 KB |
Output is correct |
11 |
Correct |
227 ms |
13128 KB |
Output is correct |
12 |
Correct |
257 ms |
13012 KB |
Output is correct |
13 |
Correct |
158 ms |
11092 KB |
Output is correct |
14 |
Correct |
169 ms |
11084 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
88 ms |
8444 KB |
Output is correct |
17 |
Correct |
231 ms |
13776 KB |
Output is correct |
18 |
Correct |
238 ms |
13108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
88 ms |
8444 KB |
Output is correct |
3 |
Correct |
231 ms |
13776 KB |
Output is correct |
4 |
Correct |
238 ms |
13108 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
1 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 |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
114 ms |
6700 KB |
Output is correct |
14 |
Correct |
103 ms |
4524 KB |
Output is correct |
15 |
Correct |
58 ms |
3424 KB |
Output is correct |
16 |
Correct |
49 ms |
2840 KB |
Output is correct |
17 |
Correct |
1 ms |
320 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 |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
444 KB |
Output is correct |
11 |
Correct |
227 ms |
13128 KB |
Output is correct |
12 |
Correct |
257 ms |
13012 KB |
Output is correct |
13 |
Correct |
158 ms |
11092 KB |
Output is correct |
14 |
Correct |
169 ms |
11084 KB |
Output is correct |
15 |
Correct |
0 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
114 ms |
6700 KB |
Output is correct |
24 |
Correct |
103 ms |
4524 KB |
Output is correct |
25 |
Correct |
58 ms |
3424 KB |
Output is correct |
26 |
Correct |
49 ms |
2840 KB |
Output is correct |
27 |
Correct |
1 ms |
320 KB |
Output is correct |
28 |
Correct |
1 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 |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
88 ms |
8444 KB |
Output is correct |
36 |
Correct |
231 ms |
13776 KB |
Output is correct |
37 |
Correct |
238 ms |
13108 KB |
Output is correct |
38 |
Correct |
1 ms |
308 KB |
Output is correct |
39 |
Correct |
0 ms |
312 KB |
Output is correct |
40 |
Correct |
1 ms |
308 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 |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
9 ms |
468 KB |
Output is correct |
46 |
Correct |
7 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
316 KB |
Output is correct |
48 |
Correct |
40 ms |
2472 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
312 KB |
Output is correct |
51 |
Correct |
4 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
125 ms |
6652 KB |
Output is correct |
56 |
Correct |
54 ms |
3812 KB |
Output is correct |
57 |
Correct |
72 ms |
3904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 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 |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
114 ms |
6700 KB |
Output is correct |
10 |
Correct |
103 ms |
4524 KB |
Output is correct |
11 |
Correct |
58 ms |
3424 KB |
Output is correct |
12 |
Correct |
49 ms |
2840 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 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 |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
88 ms |
8444 KB |
Output is correct |
22 |
Correct |
231 ms |
13776 KB |
Output is correct |
23 |
Correct |
238 ms |
13108 KB |
Output is correct |
24 |
Correct |
52 ms |
2276 KB |
Output is correct |
25 |
Correct |
129 ms |
6044 KB |
Output is correct |
26 |
Correct |
26 ms |
1596 KB |
Output is correct |
27 |
Correct |
223 ms |
13100 KB |
Output is correct |
28 |
Correct |
255 ms |
13144 KB |
Output is correct |
29 |
Correct |
235 ms |
13012 KB |
Output is correct |
30 |
Correct |
262 ms |
13116 KB |
Output is correct |
31 |
Correct |
345 ms |
13120 KB |
Output is correct |
32 |
Correct |
113 ms |
8504 KB |
Output is correct |
33 |
Correct |
242 ms |
13768 KB |
Output is correct |
34 |
Correct |
137 ms |
8396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
444 KB |
Output is correct |
11 |
Correct |
227 ms |
13128 KB |
Output is correct |
12 |
Correct |
257 ms |
13012 KB |
Output is correct |
13 |
Correct |
158 ms |
11092 KB |
Output is correct |
14 |
Correct |
169 ms |
11084 KB |
Output is correct |
15 |
Correct |
0 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
114 ms |
6700 KB |
Output is correct |
24 |
Correct |
103 ms |
4524 KB |
Output is correct |
25 |
Correct |
58 ms |
3424 KB |
Output is correct |
26 |
Correct |
49 ms |
2840 KB |
Output is correct |
27 |
Correct |
1 ms |
320 KB |
Output is correct |
28 |
Correct |
1 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 |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
308 KB |
Output is correct |
35 |
Correct |
0 ms |
312 KB |
Output is correct |
36 |
Correct |
1 ms |
308 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 |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
9 ms |
468 KB |
Output is correct |
42 |
Correct |
7 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
316 KB |
Output is correct |
44 |
Correct |
40 ms |
2472 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
312 KB |
Output is correct |
47 |
Correct |
4 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
125 ms |
6652 KB |
Output is correct |
52 |
Correct |
54 ms |
3812 KB |
Output is correct |
53 |
Correct |
72 ms |
3904 KB |
Output is correct |
54 |
Correct |
52 ms |
2276 KB |
Output is correct |
55 |
Correct |
129 ms |
6044 KB |
Output is correct |
56 |
Correct |
26 ms |
1596 KB |
Output is correct |
57 |
Correct |
223 ms |
13100 KB |
Output is correct |
58 |
Correct |
255 ms |
13144 KB |
Output is correct |
59 |
Correct |
235 ms |
13012 KB |
Output is correct |
60 |
Correct |
262 ms |
13116 KB |
Output is correct |
61 |
Correct |
345 ms |
13120 KB |
Output is correct |
62 |
Correct |
113 ms |
8504 KB |
Output is correct |
63 |
Correct |
242 ms |
13768 KB |
Output is correct |
64 |
Correct |
137 ms |
8396 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
88 ms |
8444 KB |
Output is correct |
67 |
Correct |
231 ms |
13776 KB |
Output is correct |
68 |
Correct |
238 ms |
13108 KB |
Output is correct |
69 |
Correct |
34 ms |
1584 KB |
Output is correct |
70 |
Correct |
9 ms |
652 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
49 ms |
2104 KB |
Output is correct |
73 |
Correct |
14 ms |
724 KB |
Output is correct |
74 |
Correct |
1 ms |
300 KB |
Output is correct |
75 |
Correct |
230 ms |
13088 KB |
Output is correct |
76 |
Correct |
248 ms |
13220 KB |
Output is correct |
77 |
Correct |
254 ms |
13116 KB |
Output is correct |
78 |
Correct |
281 ms |
13120 KB |
Output is correct |
79 |
Correct |
342 ms |
13120 KB |
Output is correct |
80 |
Correct |
340 ms |
13000 KB |
Output is correct |
81 |
Correct |
191 ms |
11132 KB |
Output is correct |
82 |
Correct |
183 ms |
11076 KB |
Output is correct |