This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m; cin >> n >> m;
vector<int> a(n), b(n);
for(auto &i: a) cin >> i;
for(auto &i: b) cin >> i;
auto check=[&](int x){
int bos=0;
for(int i=0; i<n; i++){
if(a[i]<=b[i]){
bos+=m;
bos-=(x+b[i]-1)/b[i];
}
else{
if(m*a[i]>=x){
bos+=m-(x+a[i]-1)/a[i];
}
else{
bos-=(x-m*a[i]+b[i]-1)/b[i];
}
}
if(-bos > (n-i)*m) return 0LL;
}
if(bos < 0) return 0LL;
return 1LL;
};
int s=0;
for(int i=60; i>=0; i--){
int tmp = s+(1LL<<i);
// cout<<tmp<<"\n";
if(check(tmp)) s=tmp;
}
cout<<s;
}
# | 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... |