#include<bits/stdc++.h>
using namespace std;
int v[] = {5,10,20,50,100,200}, mini, total, a[6];
int check(int n)
{
int u = 0, i;
for(i=5; i>=0; i--)
{
if(n >= v[i])
{
u += n/v[i];
n = n%v[i];
}
}
return u;
}
void answer(int n, int sum, int u)
{
if(n == 6)
{
if(sum >= total)
{
u += check(sum-total);
if(u < mini)
mini = u;
}
return;
}
int i;
for(i=0; i<=a[n]; i++)
answer(n+1, sum+i*v[n], u+i);
}
int main()
{
while(cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] && (a[0]+a[1]+a[2]+a[3]+a[4]+a[5] != 0))
{
double c;
cin >> c;
total = c*100;
mini = 1e9;
answer(0, 0, 0);
cout << right << setw(3) << setfill(' ') << mini << "\n";
}
return 0;
}
using namespace std;
int v[] = {5,10,20,50,100,200}, mini, total, a[6];
int check(int n)
{
int u = 0, i;
for(i=5; i>=0; i--)
{
if(n >= v[i])
{
u += n/v[i];
n = n%v[i];
}
}
return u;
}
void answer(int n, int sum, int u)
{
if(n == 6)
{
if(sum >= total)
{
u += check(sum-total);
if(u < mini)
mini = u;
}
return;
}
int i;
for(i=0; i<=a[n]; i++)
answer(n+1, sum+i*v[n], u+i);
}
int main()
{
while(cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] && (a[0]+a[1]+a[2]+a[3]+a[4]+a[5] != 0))
{
double c;
cin >> c;
total = c*100;
mini = 1e9;
answer(0, 0, 0);
cout << right << setw(3) << setfill(' ') << mini << "\n";
}
return 0;
}
Comments
Post a Comment