#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;
ll sufit(ll a,ll b){
ll wyn = a/b + 1;
if(a%b == 0)
wyn--;
return wyn;
}
bool czyok(ll x){
ll suma = 0,ile,akt;
for(int i=1;i<=n;i++){
ile = sufit(x,A[i]);
if(ile <= m){
suma += ile;
}
else{
akt = x - m*A[i];
suma += m + sufit(akt,B[i]);
}
if(suma > 1e18)
return 0;
}
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 = 1, 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... |