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;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 3e5 + 5;
ll n, m, a[NMAX], b[NMAX];
int f(ll k){
ll p = 0;
for(int i = 0; i < n; i++){
ll x = (k - 1) / a[i] + 1;
if(x <= m) p += m - x;
else p -= (k - a[i] * m - 1) / b[i] + 1;
if(p < -1e18) return 0;
}
return p >= 0;
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) cin >> b[i], a[i] = max(a[i], b[i]);
ll l = 1, r = 1e18, mid;
while(l < r){
mid = (l + r + 1) / 2;
if(f(mid)) l = mid;
else r = mid - 1;
}
cout << l;
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... |