Submission #932526

#TimeUsernameProblemLanguageResultExecution timeMemory
932526koukirocksSelf Study (JOI22_ho_t2)C++17
62 / 100
175 ms5196 KiB
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MAX=3e5+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;

ll n,m;
ll a[MAX],b[MAX];

bool ok(ll low) {
	ll all=n*m;
	for (int i=1;i<=n;i++) {
		ll org=max(a[i],b[i])*m;
		if (org>low) {
			all-=(low-1)/max(a[i],b[i])+1;
		} else {
			all-=m;
			if (org!=low) all-=(low-org-1)/b[i]+1;
		}
		if (all>oo) return true;
		if (all<-oo) return false;
	}
//	cout<<all<<"\n";
	return (all>=0);
}

int main() {
	speed;
	cin>>n>>m;
	for (int i=1;i<=n;i++) {
		cin>>a[i];
	}
	for (int i=1;i<=n;i++) {
		cin>>b[i];
	}
	ll l=1,r=1e16;
	while (l<r) {
		ll mid=(l+r+1)/2;
//		cout<<l<<" "<<mid<<" "<<r<<"\n";
		if (ok(mid)) l=mid;
		else r=mid-1;
	}
	cout<<l<<"\n";
	return 0;
}
#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...