# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1239166 | ebrambill | Self Study (JOI22_ho_t2) | C++20 | 0 ms | 0 KiB |
//In the name of GOD
#pragma GCC optimize("O3,unroll-loops)
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
const int maxN=3e5+5;
long long n, m, a[maxN], b[maxN];
int main(){
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
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 l=0, r=LLONG_MAX;
while(r-l>1){
long long mid=(r>>1)+(l>>1), cnt=0;
for (int i=1; i<=n; i++){
if(a[i]<b[i]) cnt+=(mid+b[i]-1)/b[i];
else{
long long A=((mid+a[i]-1)/a[i]<m ? (mid+a[i]-1)/a[i] : m), B=((0LL<mid-A*a[i] ? mid-A*a[i] : 0LL)+b[i]-1)/b[i];
cnt+=A+B;
}
if(cnt>n*m){
r=mid;
break;
}
}
if(r!=mid) l=mid;
}
cout <<l;
}