| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1147856 | mingga | Self Study (JOI22_ho_t2) | C++20 | 104 ms | 5136 KiB |
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 3e5 + 7;
int n, m, a[N], b[N];
bool check(long long mid) {
long long cnt = 0;
for (int i = 1; i <= n; ++i) {
if (1ll * a[i] * m >= mid) {
long long x = (1ll * a[i] * m - mid) / a[i];
cnt += x;
}
}
for (int i = 1; i <= n; ++i) {
if (1ll * a[i] * m < mid) {
long long need = mid - 1ll * a[i] * m;
need = (need + b[i] - 1) / b[i];
cnt -= need;
}
}
return cnt >= 0;
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i], a[i] = max(a[i], b[i]);
int l = 0, r = 1e18, ans = 0;
while(l <= r) {
int m = (l + r) >> 1;
if(check(m)) {
ans = m;
l = m + 1;
} else r = m - 1;
}
cout << ans << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
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... | ||||
