# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1254129 | cavid_07 | Rice Hub (IOI11_ricehub) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
bool check(int m, int pul, vector<int> vt){
int n=vt.size();
for(int i=0; i<=n-m; i++){
int med=vt[i+m/2];
int ans=0;
for(int j=i; j<min(n,i+m); j++){
ans+=abs(vt[j]-med);
}
if(ans<=pul) return true;
}
return false;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int t=1;
//cin>>t;
while(t--){
int n,r,pul;
cin>>n>>r>>pul;
vector<int> vt(n);
for(int i=0; i<n; i++){
cin>>vt[i];
}
int l=1;
int best=0;
while(l<=r){
int m=(l+r)/2;
if(check(m,pul,vt)){
l=m+1;
best=m;
}
else{
r=m-1;
}
}
cout<<best<<endl;
}
}