# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1254147 | asim | Rice Hub (IOI11_ricehub) | C++20 | 0 ms | 0 KiB |
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
// 10 ^ 8
#define ll long long
#define int int_fast32_t
#define ll int_fast64_t
bool check(int m, ll n, ll b, const vector<ll> &arr)
{
if (m > n)
{
return false;
}
for (int i = 1; i <= n - m + 1; i++)
{
ll a = 0;
for (int j = i; j <i+m; j++)
{
a += (abs(arr[j] - arr[i + m / 2]));
}
if (a <= b)
{
return true;
}
}
return false;
}
void solve()
{
ll n, r, b;
cin >> n >> r >> b;
vector<ll> arr(n + 10);
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
}
ll l1 = 1;
ll best = 1;
while (l1 <= r)
{
int m = (r + l1) / 2;
if (check(m, n, b,arr))
{
l1 = m + 1;
best = m;
}
else
{
r = m - 1;
}
}
cout << best << endl;
}
signed main()
{
IOS
solve();
}