贪心。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
const int Maxn=105;
int n,grey,cnt,maxn;
int a[Maxn],b[Maxn];
int main()
{
//freopen("painter.in","r",stdin);
//freopen("painter.out","w",stdout);
while(~scanf("%d",&n))
{
if(n==0) continue;
maxn=0,cnt=0;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
maxn=max(maxn,a[i]);
}
scanf("%d",&grey);
if(maxn%50==0) cnt=maxn/50;
else cnt=maxn/50+1;
for(int i=1;i<=n;i++)
{
b[i]=cnt*50-a[i];
}
sort(b+1,b+1+n,cmp);
while(grey>0)
{
if(b[3]>0)
{
b[1]--;b[2]--;b[3]--;//***********
grey--;
sort(b+1,b+1+n,cmp);
}
else
{
cnt++;
for(int i=1;i<=n;i++)
b[i]+=50;
sort(b+1,b+1+n,cmp);
}
}
printf("%d\n",cnt);
}
//fclose(stdin);
//fclose(stdout);
return 0;
}