#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ceilDiv(A,B) ((A)/(B) + min(1ll,(A)%(B)))
const int INF = 1e10;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin >> n >> m;
vector<int> A(n),B(n);
for(int&i:A)cin>>i;
for(int&i:B)cin>>i;
auto test = [&](int x) {
int pick = 0;
for(int i=0;i<n;i++) {
if(B[i]>=A[i])pick+=ceilDiv(x,B[i]);
else if(x<=A[i]*m)pick+=ceilDiv(x,A[i]);
else pick+=m+ceilDiv(x-A[i]*m,B[i]);
if(pick>n*m)return false;
}
return true;
};
int ans = 0;
for(int jump=(1ll<<59);jump;jump/=2) {
if(test(ans+jump))ans+=jump;
}
cout << ans << '\n';
}
# | 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... |