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
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 1e9;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin >> n >> m;
vector<int>a(n + 1),b(n + 1),c(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i];
for(int i = 1; i <= n; i++) c[i] = max(a[i],b[i]);
int l = 1,r = *max_element(c.begin(),c.end()) * m,ans = 0;
while(l <= r) {
int mid = (l + r) / 2,rest = 0;
for(int i = 1; i <= n; i++) {
if(b[i] >= a[i]) {
int need = (mid + b[i] - 1) / b[i];
rest += m - need;
continue;
}
int c = min(m,(mid + a[i] - 1) / a[i]);
int k = mid - a[i] * c;
if(k >= 1) {
rest -= (k + b[i] - 1) / b[i];
}else {
rest += m - c;
}
}
if(rest >= 0) {
ans = mid;
l = mid + 1;
}else {
r = mid - 1;
}
}
cout << ans;
return 0;
}
# | 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... |