/*
Author : detective conan
Problem : JOI21 self study
Created : 18/03/2025 10:09 UTC+7
*/
#include <bits/stdc++.h>
#define int long long
#define FOR(i, s, t) for(int i = s; i <= t; ++i)
#define rep(i, s, t) for(int i = s; i >= t; --i)
#define DB(n, s) cout << n << s
#define ANS(n, s) DB(n, s)
#define mod (int)(1e9 + 7)
#define HAVE_TESTCASE false
#define pb push_back
#define eb emplace_back
#define em emplace
#define ph push
#define conan cin.tie(nullptr)->sync_with_stdio(false);
using namespace std;
using u32 = unsigned;
using i64 = int64_t;
using u64 = unsigned i64;
const int MAX_N = 3e5 + 20;
int n, m, a[MAX_N], b[MAX_N];
void solve(){
cin >> n >> m;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) cin >> b[i];
int l = 0, r = 1e18, ans = -1;
while(l <= r){
int mid = (l + r) >> 1ll;
int left = n*m;
FOR(i, 1, n){
int tmp = mid;
if(a[i] > b[i]){
int times = (tmp + a[i] - 1) / a[i];
int use = min(times, m);
left -= use;
tmp -= a[i]*use;
}
if(tmp > 0ll){
int times = (tmp + b[i] - 1) / b[i];
left -= times;
}
if(left < 0ll) break;
}
if(left >= 0ll) ans = mid, l = mid + 1;
else r = mid - 1;
}
ANS(ans, '\n');
}
int32_t main(){
conan;
int t = 1;
if(HAVE_TESTCASE) cin >> t;
while(t--) solve();
}
# | 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... |