http://acm.pku.edu.cn/JudgeOnline/problem?id=1042
Код:
#include<iostream>
using namespace std;
int main() {
int i,j,k,g,n,h,ans,tot,tt=0,f[32],d[32],t[32],now[32],tnow[32],times[32];
while (scanf("%d",&n),n) {
if (tt++) printf("\n");
scanf("%d",&h);
h*=12;
for (i=0;i<n;++i) {
scanf("%d",&f[i]);
now[i]=f[i];
}
for (i=0;i<n;++i)
scanf("%d",&d[i]);
for (i=0;i<n-1;++i)
scanf("%d",&t[i]);
memset(times,0,sizeof(times));
for (ans=i=0;i<n&&h>0;++i)
{
for (j=0;j<i;++j)
now[j]=f[j];
memset(tnow,0,sizeof(tnow));
for (tot=k=0;k<h;++k)
{
for (g=0,j=1;j<=i;++j)
if (now[j]>now[g])
g=j;
tot+=now[g];
now[g]-=d[g];
if (now[g]<0)
now[g]=0;
++tnow[g];
}
if (tot>ans)
{
ans=tot;
for (j=0;j<n;++j)
times[j]=tnow[j];
}
else if (tot==ans)
{
for (j=0;j<n;++j)
if (tnow[j]!=times[j])
break;
if (j<n&&tnow[j]>times[j])
for (g=j;g<n;++g)
times[g]=tnow[g];
}
h-=t[i];
}
for (i=0;i<n-1;++i)
printf("%d, ",times[i]*5);
printf("%d\nNumber of fish expected: %d\n",times[n-1]*5,ans);
}
return 0;
}