#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool check(int dis, int n, vector < ll > &pre, vector < ll > &x, ll B) {
ll ans = 1e16;
for (int l = 1; l + dis - 1 <= n; l++) {
int r = l + dis - 1;
int med = (l + r) >> 1; // x[l] -> x[r] => x[l] -> x[med] and x[med] -> x[r]
ll mb = x[med] * (med - l + 1) - (pre[med] - pre[l - 1]) + (pre[r] - pre[med - 1]) - x[med] * (r - med + 1);
ans = min(ans, mb);
}
return ans <= B;
}
int besthub(int R, ll L, ll X[], ll B) {
int n = R;
vector < ll > pre(n + 1), x(n + 1);
pre[0] = 0;
for (int i = 1; i <= n; i++) {
x[i] = X[i - 1];
pre[i] = pre[i - 1] + x[i];
}
int l = 1, r = n;
while(r - l > 1) {
int mid = (l + r) >> 1;
if (check(mid, n, pre, x, B))
l = mid;
else
r = mid - 1;
}
if (check(r, n, pre, x, B))
return r;
else if (check(l, n, pre, x, B))
return l;
else
return 0;
}
Compilation message
/usr/bin/ld: /tmp/ccBjIO0n.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