//JOI 2022 Final round
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1e18;
bool possible(int x, int n, int m, vector<int>& a, vector<int>& b){
int d=0;
for(int i=0; i<n; i++){
if(a[i] > b[i]){
int da = (x+a[i]-1)/a[i];
int db = 0;
if(da > m){
da = m;
int x2 = x - (da*a[i]);
assert(0<x2);
db = (x2 + b[i]-1)/b[i];
}
d += da + db;
}
else{
int db = (x+b[i] -1)/b[i];
d += db;
}
}
return d <= (n*m);
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
vector<int> b(n);
for(int i=0; i<n; i++){
cin >> b[i];
}
int l=1; int r=INF;
int ans=1;
while(l <= r ){
int mi=l+(r-l)/2;
if(possible(mi, n, m, a, b)){
ans=mi;
l=mi+1;
}
else{
r=mi-1;
}
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
174 ms |
5016 KB |
Output is correct |
12 |
Correct |
176 ms |
4984 KB |
Output is correct |
13 |
Correct |
171 ms |
5008 KB |
Output is correct |
14 |
Incorrect |
427 ms |
5008 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
228 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 |
73 ms |
2660 KB |
Output is correct |
10 |
Correct |
50 ms |
1892 KB |
Output is correct |
11 |
Correct |
38 ms |
1492 KB |
Output is correct |
12 |
Correct |
29 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 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 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
174 ms |
5016 KB |
Output is correct |
12 |
Correct |
176 ms |
4984 KB |
Output is correct |
13 |
Correct |
171 ms |
5008 KB |
Output is correct |
14 |
Incorrect |
427 ms |
5008 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
228 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 |
73 ms |
2660 KB |
Output is correct |
10 |
Correct |
50 ms |
1892 KB |
Output is correct |
11 |
Correct |
38 ms |
1492 KB |
Output is correct |
12 |
Correct |
29 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 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 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
174 ms |
5016 KB |
Output is correct |
12 |
Correct |
176 ms |
4984 KB |
Output is correct |
13 |
Correct |
171 ms |
5008 KB |
Output is correct |
14 |
Incorrect |
427 ms |
5008 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |