Unfortunately, Igor could only get v liters of paint. He did the math and concluded that digitd requires ad liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number.
Help Igor find the maximum number he can write on the fence.
Input
The first line contains a positive integer v(0 ≤ v ≤ 106). The second line contains nine positive integersa1, a2, ..., a9(1 ≤ ai ≤ 105).
Output
Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.
Sample test(s)
Input
5
5 4 3 2 1 2 3 4 5
Output
55555
Input
2
9 11 1 12 5 8 9 10 6
Output
33
Input
0
1 1 1 1 1 1 1 1 1
Output
-1
题意:给出颜料总数,还有1~9每个数字需要的颜料数,问将能刷出的最大数字是多少
思路:贪心即可
#include#include #include using namespace std; int main() { int a[10],sum,minn,k,i,j,cnt,r; while(~scanf("%d",&sum)) { minn = 1000000005; k = 0; for(i = 1; i<=9; i++) { scanf("%d",&a[i]); if(a[i] 0)//总颜料还没用完,找出与最小花费长度相等的最大数 { int x = 0; for(i = 1; i<=9; i++) { int s = sum-a[i];//减去这个数字的花费 if(s<0)//这个数字会使颜料用完,换下一个颜料 continue; if(s/minn == cnt-1 && x