Codeforces Round #202 (Div. 2) B. Color the Fence

来源:互联网 发布:nginx怎么配置ssl证书 编辑:程序博客网 时间:2024/05/22 06:07
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.

Sample test(s)
input
55 4 3 2 1 2 3 4 5
output
55555
input
29 11 1 12 5 8 9 10 6
output
33
input
01 1 1 1 1 1 1 1 1
output
-1
先凑位数多的,再凑首个数字大的,就可以了!
#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;#define M 100050struct node{    int p,i;}pri[14];bool cmp(node a,node b){    if(a.p!=b.p)return a.p<b.p;    else return a.i>b.i;}int main(){    int v,i;    while(scanf("%d",&v)!=EOF){        for(i=1;i<=9;i++)        scanf("%d",&pri[i].p),pri[i].i=i;        sort(pri+1,pri+10,cmp);        int n=v/pri[1].p;        if(n==0)printf("-1\n");        else {            int res=v-n*pri[1].p,maxx=pri[1].i,kk=0;            while(1){                int temp=-1;maxx=pri[1].i;                for(i=1;i<=9;i++){                    if(res+pri[1].p>=pri[i].p&&maxx<pri[i].i){                        temp=i;                        maxx=pri[i].i;                    }                }                if(temp==-1)break;                res=res-pri[temp].p+pri[1].p;                printf("%d",maxx);kk++;            }            for(;kk<n;kk++)printf("%d",pri[1].i);            printf("\n");        }    }    return 0;}


原创粉丝点击