Submission #1239222

#TimeUsernameProblemLanguageResultExecution timeMemory
1239222ebrambillSelf Study (JOI22_ho_t2)C++17
0 / 100
1096 ms4936 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];

bool can(long long x){
	long long cnt=0;
	for (long long i=1; i<=n; i++){
		cnt+=(a[i]<b[i] ? (x+b[i]-1)/b[i] : (m*a[i]>=x ? (x+a[i]-1)/a[i] : m+(x-m*a[i]+b[i]-1)/b[i]));
		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];
	for (long long i=1; i<=n; i++) cin >>b[i];

	long long l=0, r=LLONG_MAX;
	while(r-l>1){
		long long mid=(r>>1)+(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...