#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 69;
int seg[4*maxn];
int a[maxn];
int n;
void Build(int l, int r, int pos){
if (l==r){
seg[pos] = a[l];
return;
}
int mid = (l+r)/2;
Build(l, mid, pos*2);
Build(mid + 1, r, pos*2 + 1);
seg[pos] = seg[pos * 2] + seg[pos * 2 + 1];
}
int Query(int l, int r, int pos, int ql, int qr){
if (l>r) return 0;
if (l>=ql && r<=qr)
return seg[pos];
else if (l>qr || ql>r) return 0;
int mid = (l+r)/2;
return Query(l, mid, pos*2, ql, qr) + Query(mid + 1, r, pos*2 + 1, ql, qr);
}
bool check(int l, int r, int B){
int mid = (l+r)/2;
int pos = a[mid];
int val = (mid - l + 1) * pos - Query(1, n, 1, l, mid);
val += Query(1, n, 1, mid, r) - (r - mid + 1) * pos;
return val <= B;
}
int besthub(int R, int L, int X[], long long B)
{
n = R;
for (int i=1; i<=n; i++){
a[i] = X[i];
}
Build(1, n, 1);
int ans = 0;
int r = 0;
for (int l=1; l<=n; l++){
while (r!=n && check(l, r+1, B))
r++;
ans = max(ans, r-l+1);
}
return ans;
}
Compilation message
/usr/bin/ld: /tmp/ccpp6MGB.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