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 int long long
using namespace std;
#define boost ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const int N = 1e6 + 12, INF = 1e9 + 7;
signed main () {
boost
int n, m;
cin >> n >> m;
vector<int>a(n), b(n);
for(int i = 0; i < n; ++i){
cin >> a[i];
}
for(int i = 0; i < n; ++i){
cin >> b[i];
}
auto just = [&](int p){
int t = 0;
for(int i = 0; i < n; ++i){
if(b[i] > a[i]){
int just1 = (p + b[i] - 1) / b[i];
t += just1;
} else {
if(a[i] * m >= p){
int just2 = (p + a[i] - 1) / a[i];
t += just2;
} else {
int just2 = m;
int just1= (p - a[i] * m + b[i] - 1) / b[i];
t += just2 + just1;
}
}
if(t > n * m) return false;
}
if(t <= n * m){
return true;
} else {
return false;
}
};
int l = 0, r = 1e18;
while(r - l > 1){
int m = (l + r) / 2;
if(just(m)){
l = m;
} else {
r = m;
}
}
if(just(r)){
cout << r;
} else {
cout << l;
}
}
# | 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... |