您的位置:首页 > Web前端

(贪心)Color the Fence - CF 202 Div2B

2017-02-07 09:42 399 查看
B. Color the Fence

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.

Unfortunately, Igor could only get v liters of paint. He did the math and concluded that digit d 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 integers a1, 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.

Examples

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

http://codeforces.com/contest/349/problem/B
给你染料的体积 以及 数字1~9 的需要的染料体积

求 能染出来的最大的数

最大的数字:

1. 位数多

2. 在1前提下高位尽量大

 

#include <bits/stdc++.h>

using namespace std;

int main()
{
int i,v,minnum;
int sum,cnt,flag;
int num[11];

while (cin>>v)
{
minnum=1e6;
sum=0;
cnt=0;

for (i=1; i<=9; i++)
{
cin>>num[i];
if (num[i] <= minnum)
{
minnum=num[i];  ///耗费染料最少的数 染出来位数多
}
}

cnt=v/minnum;  ///cnt 能染出来的最大位数
flag=cnt;
sum=1;

while (flag--)
{
for (i=9; i>=1; i--)  /// 从高位开始染
{
if (v>=num[i] && (v-num[i])/minnum + sum ==  cnt) /// sum+cnt==the longest lenght  notice : v>=num[i]
{
v-=num[i];
sum++;  ///已经染得位数
cout<<i;
break;  ///染完继续下一位
}
}
}

if (!cnt)
{
cout<<"-1";
}
cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  贪心 CF349B codeforce