#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e5;
int a[MAX_N], b[MAX_N];
int main() {
int n, m;
cin >> n >> m;
for ( int i = 0; i < n; i++ )
cin >> a[i];
for ( int i = 0; i < n; i++ )
cin >> b[i];
long long l = 0, r = 1.5e18;
while ( r - l > 1 ) {
long long mid = (l + r) / 2;
long long freeClasses = (long long)n * m, busyClasses = 0;
for ( int i = 0; i < n; i++ ) {
if ( a[i] > b[i] ) {
if ( (long long)a[i] * m >= mid )
freeClasses -= (mid + a[i] - 1) / a[i];
else {
freeClasses -= m;
busyClasses += (mid - (long long)m * a[i] + b[i] - 1) / b[i];
}
} else
busyClasses += (mid + b[i] - 1) / b[i];
}
if ( freeClasses >= busyClasses )
l = mid;
else
r = mid;
}
cout << l << "\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... |