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 <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
ll n, m;
cin >> n >> m;
vector <ll> a(n);
vector <ll> b(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
for (int i = 0; i < n; i++)
a[i] = max(a[i], b[i]);
ll l = 1, r = 1000000000000000001;
ll granica = n*m;
while (l < r){
ll mid = (l+r)/2;
ll potrebno = (ll) 0;
for (int i = 0; i < n; i++){
if (potrebno > granica)
break;
ll maksa = mid/a[i];
if (mid%a[i] != 0)
maksa++;
potrebno += min(maksa, m);
ll iskor = min(maksa, m);
ll maksb = (mid- iskor*a[i])/b[i];
if(mid-iskor*a[i] < 0)
continue;
if((mid - iskor*a[i])%b[i] != 0)
maksb++;
potrebno += maksb;
}
if (potrebno <= granica)
l = mid + 1;
else
r = mid;
}
cout << l - 1;
}
# | 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... |