# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1115902 | TrieTr | Self Study (JOI22_ho_t2) | C++14 | 133 ms | 15176 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
void local() {
#define taskname ""
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
}
#define ll long long
#define int long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template<class X, class Y> bool mini(X &a, const Y &b) {return (a > b) ? a = b, true : false;}
template<class X, class Y> bool maxi(X &a, const Y &b) {return (a < b) ? a = b, true : false;}
const int N = 1e6 + 5;
int n, m;
int a[N], b[N];
bool check(ll x) {
ll cnt = 0;
for(int i = 1; i <= n; i++) {
if(a[i] > b[i]) {
ll useA = min(m * 1ll, (x + a[i] - 1 ) / a[i]);
ll useB = max(0ll, (x - useA * a[i] + b[i] - 1) / b[i]);
cnt += useA + useB;
}
else cnt += (x + b[i] - 1) / b[i];
if(cnt > 1ll * n * m) return false;
}
return cnt <= 1ll * n * m;
}
signed main() {
fastio; local();
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i];
ll lo = 1, hi = 1e18, res = 0;
while(lo <= hi) {
ll mid = (lo + hi) >> 1;
if(check(mid)) lo = (res = mid) + 1;
else hi = mid - 1;
}
cout << res;
}
Compilation message (stderr)
# | 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... |