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 <iostream>
#include <vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
using ll = long long;
long long A[300050], B[300050];
int main(){
ll N, M;
cin >> N >> M;
loop(i,0,N) cin >> A[i];
loop(i,0,N) cin >> B[i];
loop(i,0,N) A[i] = max(A[i], B[i]);
ll ok = 0, ng = 1LL << 60;
auto check = [&](ll x) -> bool {
ll day = 0;
for(ll i = 0; i < N; i++){
if(x <= A[i] * M) day += (x + A[i] - 1) / A[i];
else day += M + (x - A[i] * M + B[i] - 1) / B[i];
if(day > N * M) return 0;
}
return 1;
};
while(ng - ok > 1){
const ll mid = (ng + ok) / 2;
if(check(mid)) ok = mid;
else ng = mid;
}
cout << ok << endl;
}
# | 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... |