#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
using ll  = long long;
using ld  = long double;
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pi3 = pair<pii, ll>;
#define IOS               ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define F                 first
#define S                 second
#define sz(x)             x.size()
#define all(x)            x.begin(), x.end()
#define pb                push_back
#define cl                clear
#define minr(a, b)        a = min(a, b);
#define maxr(a, b)        a = max(a, b);
#define shit              cout << "shit\n" << flush;
#define tl                while(1&1) continue;
#define FOR(i, st, nd)    for(ll i = st; i <= nd; i++)
#define rand(l, r)        uniform_ll_distribution<ll64_t>(l,r)(rng)
random_device device;     default_random_engine rng(device());
const ll Mod    = 1e9 + 7; //998244353;
const ll LG     = 64;
const ll SQ     = 500;
const ll Inf    = 2e9 + 10;
const ll maxN   = 3e5 + 10;
ll n, m;
ll a[maxN];
ll b[maxN];
bool check(ll x) {
	ll need = 0;
	for(ll i = 1; i <= n; i++) {
		if(a[i]*m >= x) {
			need += (x+a[i]-1)/a[i];
		}
		else {
			ll rem = x - a[i]*m;
			need += m;
			need += (rem+b[i]-1)/b[i];
		}
	}
	return (need <= 1LL*n*m);
}
int main() {
	IOS;
	cin >> n >> m;
	for(ll i = 1; i <= n; i++)
		cin >> a[i];
	for(ll i = 1; i <= n; i++) {
		cin >> b[i];
		a[i] = max(a[i], b[i]);
	}
	ll l = 0;
	ll r = 1e18+1;
	while(l+1 < r) {
		ll mid = (l+r)>>1;
		if(check(mid))
			l = mid;
		else
			r = mid;
	}
	cout << l;
}
| # | 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... |