#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define st first
#define nd second
#define pb push_back
const int maxn = 3e5+7;
ll A[maxn];
ll B[maxn];
ll n,m;
bool czyok(ll x){
ll suma = 0,ile,akt;
for(int i=1;i<=n;i++){
ile = ceil((double)x/A[i]);
if(ile <= m){
suma += ile;
}
else{
akt = x - m*A[i];
suma += m + ceil((double)akt/B[i]);
}
}
if(suma <= n*m)
return 1;
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>A[i];
}
for(int i=1;i<=n;i++){
cin>>B[i];
A[i] = max(A[i],B[i]);
}
ll pocz = 0, kon = 1e18+7, sro;
while(pocz < kon){
sro = (pocz+kon+1)/2;
if(czyok(sro)){
pocz = sro;
}
else{
kon = sro-1;
}
}
cout<<pocz<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |