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

原创 2016年05月31日 15:19:12
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

#include <cstdio>
#include <algorithm>
using namespace std;
int V;
int a[9];

int main()
{
    while (scanf("%d", &V) != EOF){
        int min1 = 1000000;
        for (int i = 1; i <= 9; i++){
            scanf("%d", &a[i]);
            if (a[i] < min1)
                min1 = a[i];
        }
        if (V < min1){
            printf("-1\n");
            continue;
        }
        for (int i = V / min1 - 1; i >= 0; i--){    //从最多可以染的数目开始  
            for (int j = 9; j > 0; j--){
                //扫描所有的可以满足大于当前要染的数字,以及所要消耗的之后的剩余对min除还能保持>=i,就可以染当前的数字
                if (V >= a[j] && (V - a[j]) / min1 >= i){
                    printf("%d", j);
                    V -= a[j];
                    break;
                }
            }
        }
        printf("\n");
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

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

B. Color the Fencetime limit per test:2 secondsmemory limit per test:256 megabytesinput:standard inp...

(贪心)Color the Fence - CF 202 Div2B

B. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input sta...

CF#202DIV2:B. Color the Fence

http://codeforces.com/contest/349/problem/B Igor has fallen in love with Tanya. Now Igor wants to sh...

Codeforces Round #202 (Div. 2) (A、B、C、D)

这场比赛发挥的不太好吧,当时只做了两题,第三题当时已经想到正解了,但不知发什么神经去想别的解法了。。。果然晚上的状态不好啊。   A. Cinema Line      非常水……一队人排队买票,每个...
  • qian99
  • qian99
  • 2013年09月29日 16:38
  • 1103

Codeforces Round #202 (Div. 2)C. Mafia(思维)

C. Mafiatime limit per test:2 secondsmemory limit per test:256 megabytesinput:standard inputoutput:s...

Codeforces Round #256 (Div. 2) C. Painting Fence (搜索 or DP)

【题目链接】:click here~~ 【题目大意】:题意:你面前有宽度为1,高度给定的连续木板,每次可以刷一横排或一竖列,问你至少需要刷几次。 Sample Input Input 5 2...

Codeforces Round #355 (Div. 2) A. Vanya and Fence (水题)

A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes ...

Codeforces Round #355 (Div. 2)- Vanya and Fence(模拟)

A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes ...

Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)

Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)

Codeforces #211 (Div. 2) B. Fence

B. Fence time limit per test 1 second memory limit per test 256 megabytes input st...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces Round #202 (Div. 2) B. Color the Fence
举报原因:
原因补充:

(最多只允许输入30个字)