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>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n; ll m;
vector<ll> a, b;
bool check(ll X){
__int128 e = 0;
for(int i = 0; i < n; i++){
ll c = m*a[i];
if(c >= X){
e+=m-((X+a[i]-1)/a[i]);
}
else{
c = X-c;
e-=(c+b[i]-1)/b[i];
}
}
if(e >= 0) return 1;
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
a.resize(n), b.resize(n);
for(ll &x: a) cin >> x;
for(ll &x: b) cin >> x;
for(int i = 0; i < n; i++) a[i] = max(a[i], b[i]);
ll a = 1, b = 2e18;
while(a < b){
ll md = (a+b+1)/2;
if(check(md)) a = md;
else b = md-1;
}
cout << a << "\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... |