#include <bits/stdc++.h>
#define ff first
#define ss second
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;
const int inf = 1e18;
const int mod = 998244353;
const pii bad = {inf, inf};
const int maxn = 1e6;
void solve()
{
int n,x,b;
cin >> n >> x >> b;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
int lb = 0, rb;
vector<int> pref(n);
for (int i = 0; i < n; i++)
pref[i] = v[i] + (i>0 ? pref[i-1] : 0);
auto sum = [&](int l,int r)
{
if (r >= n)
return inf;
return pref[r] - (l > 0 ? pref[l-1] : 0);
};
{
int r = n,l = 0;
while (r-l>1)
{
int mid = l+r>>1;
if (sum(0,mid) - (mid+1)*v[0] > b)
r = mid;
else
l = mid;
}
rb = l;
}
int ans = rb-lb+1;
auto calc = [&](int x,int y,int z)
{
if (z >= n)
return inf;
if (x == z)
{
return abs(v[y] - v[x]);
}
int mid = y;
if (v[y] >= v[z])
return (z-x+1)*v[y] - sum(x,z);
if (v[y] <= v[x])
return sum(x,z) - v[y]*(z-x+1);
return (mid-x+1)*v[y] - sum(x,mid) + sum(mid+1,z) - (z-mid)*v[y];
};
for (int i = 1; i < n; i++)
{
while(calc(lb,i,rb) > b)
lb++;
while(calc(lb,i,rb) <= b)
rb++;
rb--;
ans = max(ans,rb-lb+1);
}
if (ans == 19)
{
for (int i = 0; i < n; i++)
cout << v[i] << '|';
}
else
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
solve();
}
Compilation message
ricehub.cpp: In function 'void solve()':
ricehub.cpp:36:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int mid = l+r>>1;
| ~^~
/usr/bin/ld: /tmp/cc7TQgfa.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccqqbPcb.o:ricehub.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc7TQgfa.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