# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1123753 | Neco_arc | Self Study (JOI22_ho_t2) | C++20 | 84 ms | 2632 KiB |
#include <bits/stdc++.h>
#define ll long long
#define name "Self Study"
#define fi(i, a, b) for(int i = a; i <= b; ++i)
#define fid(i, a, b) for(int i = a; i >= b; --i)
#define maxn (int) (2e5 + 7)
using namespace std;
ll n, k;
ll a[maxn], b[maxn];
ll cc(ll x, ll y) { return (x + y - 1) / y; }
bool check(ll X) {
ll S = 0;
fi(i, 1, n) {
ll sl = cc(X, a[i]);
if(sl > k) {
S += k + cc(X - k * a[i], b[i]);
}
else S += sl;
if(S > n * k) return 0;
}
return S <= n * k;
}
void solve() {
cin >> n >> k;
fi(i, 1, n) cin >> a[i];
fi(i, 1, n) cin >> b[i];
fi(i, 1, n) a[i] = max(a[i], b[i]);
ll l = 0, r = 1ll << 60;
while(l <= r) {
ll mid = (l + r) / 2;
if(check(mid)) l = mid + 1;
else r = mid - 1;
}
cout << r;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
if(fopen(name".inp", "r")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
solve();
}
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... |