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;
long long n,m;
long long a[300005], b[300005];
long long l, r, mid;
bool check(long long x) {
long long extra = 0, need = 0;
for(int i=1; i<=n; i++) {
if(a[i] > b[i]){ // study in class
long long needed = (x + a[i] - 1) / a[i];
if(needed > m) {
need += (x - a[i] * m + b[i] - 1) / b[i];
if(need > 1e18) return false;
} else {
extra += m - needed;
}
} else { // study at any time
extra += m;
need += (x + b[i] - 1) / b[i];
if(need > 1e18) return false;
}
}
if(extra>=need) return true;
else return false;
}
int main() {
cin >> n >> m;
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=n; i++) cin >> b[i];
l = 0; r = 1e18;
while(l<r) {
mid = (l+r+1)/2;
if(check(mid)) l = mid;
else r = mid - 1;
}
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... |