Submission #1242050

#TimeUsernameProblemLanguageResultExecution timeMemory
1242050ebrambillSelf Study (JOI22_ho_t2)C++17
100 / 100
141 ms5136 KiB
//In the name of GOD

#include <bits/stdc++.h>
using namespace std;

const long long maxN=3e5+5;
long long n, m, a[maxN], b[maxN], maxi;

bool can(long long x){
	long long cnt=0;
	for (long long i=1; i<=n; i++){
		if(a[i]<b[i]) cnt+=(x+b[i]-1)/b[i];
		else{
			long long A=min((x+a[i]-1)/a[i], 1LL*m), B=(max(0LL, x-A*a[i])+b[i]-1)/b[i];
			cnt+=A+B;
		}
		if(cnt>n*m) return false;
	}
	return true;
}

int main(){
	cin.tie(0); 
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin >>n >>m;
	for (long long i=1; i<=n; i++){
	   	cin >>a[i];
		maxi=max(maxi, a[i]);
	}
	for (long long i=1; i<=n; i++){
	   	cin >>b[i];
		maxi=max(maxi, b[i]);
	}

	long long l=0, r=m*maxi+1;
	while(r-l>1){
		long long mid=(r+l)>>1;
		if(can(mid)) l=mid;
		else r=mid;
	}
	cout <<l;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...