# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1027629 | vjudge1 | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int besthub(int n, int l, int x[], long long b)
{
int a[l+1];
memset(a, 0, sizeof(a));
for(int i=0; i<n; i++)
a[x[i]]=1;
long long max_rez=-1, sol=0;
for(int i=1; i<=l; i++)
{
int bb=b;
int rezz=a[i];
for(int j=i-1, k=i+1; j>0 || k<=l; k++, j--)
{
if(j>0 && a[j]==1 && bb-(i-j)>=0)
{
bb-=(i-j);
rezz++;
}
else if(j>0 && bb-(i-j)<0)
break;
if(k<=l && a[k]==1 && bb-(k-i)>=0)
{
bb-=(k-i);
rezz++;
}
else if(k<=l && bb-(k-i)<0)
break;
}
if(max_rez<rezz)
{
max_rez=rezz;
sol=i;
}
}
return sol;
}
int main()
{
int r, l;
long long b;
cin>>r>>l;
int x[r];
for(int i=0; i<r; i++)
cin>>x[i];
cin>>b;
cout<<besthub(r, l, x, b);
return 0;
}