#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
ll f[N];
bool check (ll x, ll b, int l, int r, vector<ll> &a) {
int j = upper_bound(a.begin(), a.end(), x) - a.begin();
j = min(j, r - 1);
ll sum = x * (j - l + 1) - (f[j] - f[l - 1]) + (f[r] - f[j]) - x * (r - j);
// if (x == 8 && l == 2 && r == 5) {
// cout << f[r]- f[j] << '\n';
// cout << j + 1 << ' ' << sum << '\n';
// cout << (sum <= b) << '\n';
// }
return (sum <= b);
}
bool ok (int k, ll b, int n, vector<ll> &a) {
for (int i = k; i <= n; i++) {
ll med = (f[i] - f[i - k]) / k;
if (check(med, b, i - k + 1, i, a)) {
// if (k == 4) {
// cout << i - k + 1 << ' ' << i << '\n';
// }
return true;
}
if (check(med + 1, b, i - k + 1, i, a)) {
// if (k == 4) {
// cout << i - k + 1 << ' ' << i << '\n';
// }
return true;
}
if (check(med - 1, b, i - k + 1, i, a)) {
// if (k == 4) {
// cout << i - k + 1 << ' ' << i << ' ' << med - 1 << '\n';
// }
return true;
}
}
return false;
}
int besthub (int r, int l, vector<ll> x, ll b) {
for (int i = 0; i < r; i++) {
f[i + 1] = f[i] + x[i];
}
int ans = -1;
int lo = 0, hi = r;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (ok(mid, b, r, x)) {
ans = mid;
lo = mid + 1;
}
else {
hi = mid - 1;
}
}
return ans;
}
// signed main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
//
// cout << besthub(5, 20, {1, 2, 10, 12, 14}, 6);
//
// return 0;
// }
Compilation message
/usr/bin/ld: /tmp/ccRF9Epg.o: in function `main':
grader.cpp:(.text.startup+0xae): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status