# The second blog, novice on the road, intensive training is very rich

2021-09-15 05:07:47

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
```55 4 3 2 1 2 3 4 5

1.
2.
```
output
```55555

1.
```
input
```29 11 1 12 5 8 9 10 6

1.
2.
```
output
```33

1.
```
input
```01 1 1 1 1 1 1 1 1

1.
2.
```
output
```-1

1.
```

brief introduction ： I'll give you the numbers first v, Show the value you have , Then I'll give you a sequence a[9] Means you want to write 1 To 9 The cost of these figures . Ask the maximum you can write ;

Answer key ： First, find the length of the maximum value with the minimum cost , Then greedily take the maximum value of each digit ;

The code is as follows ：

```#include <stdio.h>
#include <algorithm>
#include <string.h>
#include<iostream>
#define ll long long
using namespace std;
const int maxn=1e5+5;
int a[10];
int b[maxn];
struct node
{
int id,pri;
double xjb;
bool operator <(const node a)
{
if(pri!=a.pri)
return pri<a.pri;
else
return id>a.id;
}
}st[10];
int v;
int main()
{
scanf("%d",&v);
for(int i=1;i<=9;i++)
{
scanf("%d",&a[i]);
st[i].id=i;
st[i].pri=a[i];
st[i].xjb=double(i)/double(a[i]);
}
sort(st+1,st+10);//ll ans=0;
bool flag=false;
int t=v/st[1].pri;
int tmp=v,sd=t;
for(int i=0;i<t;i++)
{
for(int j=9;j>=1;j--)
{
if((sd-1)*st[1].pri+a[j]<=tmp)
{
cout<<j;
sd--;
tmp-=a[j];
flag=true;
break;
}

}
}
if(flag)cout<<endl;
else cout<<-1<<endl;

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
```

https://chowdera.com/2021/09/20210909115113535k.html