#include "ricehub.h"
#include <bits/stdc++.h>
#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
ricehub.cpp: In function 'long long int besthub(long long int, long long int, long long int*, long long int)':
ricehub.cpp:55:13: error: 'max' was not declared in this scope; did you mean 'std::max'?
55 | ans = max(ans, r-l+1);
| ^~~
| std::max
In file included from /usr/include/c++/10/algorithm:62,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
from ricehub.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: 'std::max' declared here
3486 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~