Codeforces Round #202 (Div. 2)B. Color the Fence(贪心,模拟)

来源:互联网 发布:云端是什么软件 编辑:程序博客网 时间:2024/05/29 08:44

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
题意:给你n元,构成数字1-9的花费为ai,问能组成的最大数字是多少。
题解:首先数字数越多越好,当数字数确定后,看能不能把将数字换成更大的。有点模拟的意思。
代码:

#include <bits/stdc++.h>#define ll long long#define bababba printf("!!!!!!!!!\n")using namespace std;int cnt;map<int,int>mp;const int N=1e7+10;int ans[N];struct node{    int id,pi;    bool operator <(const node &t)const{       return pi<t.pi||(pi==t.pi&&id>t.id);    }}a[100];void save(){    for(int i=1;i<=cnt;i++)    {        ans[i]=a[1].id;    }}void print(){    for(int i=1;i<=cnt;i++)    {        printf("%d",ans[i]);    }    printf("\n");}int main(){    int n;    scanf("%d",&n);    for(int i=1;i<=9;i++)    {        int x;        scanf("%d",&x);        a[i].id=i;        a[i].pi=x;    }    sort(a+1,a+10);    for(int i=1;i<=9;i++)    {        mp[a[i].id]=i;    }     cnt=n/a[1].pi;     if(cnt==0)     {         printf("-1\n");         return 0;     }    save();    if(n%a[1].pi==0)    {        print();    }    else    {        int y=n%a[1].pi;        for(int i=1;i<=cnt;i++)        {            for(int j=9;j>=1;j--)            {                if(y+a[mp[ans[i]]].pi>=a[mp[j]].pi&&j>ans[i])//j>ans[i]不加也能过,但我感觉是错的。。                {                    int t=ans[i];                    ans[i]=j;                    y=y+a[mp[t]].pi-a[mp[j]].pi;                    break;                }            }        }        print();    }    return 0;}
0 0
原创粉丝点击