Submission #864793

#TimeUsernameProblemLanguageResultExecution timeMemory
864793serifefedartarSelf Study (JOI22_ho_t2)C++17
100 / 100
200 ms11408 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 20; 
const ll MAXN = 3e5 + 100;

vector<ll> A, B;
ll N, M;
bool check(ll x) {
	ll need = 0;
	for (int i = 1; i <= N; i++) {
		if (M * A[i] >= x)
			need += (x + A[i] - 1) / A[i];
		else
			need += M + (x - A[i] * M + B[i] - 1) / B[i];
		if (need > N * M)
			return false;
	}
	return (need <= N * M);
}

int main() {
	fast
	cin >> N >> M;

	A = vector<ll>(N+1);
	B = vector<ll>(N+1);
	for (int i = 1; i <= N; i++)
		cin >> A[i];
	for (int i = 1; i <= N; i++)
		cin >> B[i];
	for (int i = 1; i <= N; i++)
		A[i] = max(A[i], B[i]);

	ll L = 0;
	ll R = 2 * 1e18;
	ll ans = -1;
	while (L <= R) {
		ll mid = L + (R-L)/2;
		if (check(mid)) {
			L = mid + 1;
			ans = mid;
		} else
			R = mid - 1;
	}
	cout << ans << "\n";
}
#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...