CodeForces 349B Color the Fence

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

题目大意:用一定量的油漆绘出一个最大的数字,第一行给出数V代表油漆的总量,第二行九个数分          别代表1-9这9个数字所需的所耗费的油漆量,问能绘出的最大数字是多少。
思路:我们用一个变量MIN表示1-9这9个数字所耗油漆量的最小值,那么V/MIN就表示V升油漆可绘       制的数字的最大长度。这样最大长度就有了,接下来我们开始找最大的数。从最高位开           始找,从大到小暴力9个数字,若发现某个数字可以绘制并且绘制后不会改变最大长度(例       如V = 5, 9个数分别为2、2、3、4、5、6、7、8、9,那么最大长度为2,当选择数字           1,2,3时不会改变最大长度,但若选择4时,便无法再继续选择,此时最大长度为1)时,
      就选用这个数,然后退出。不断循环,直到无法选择为止。
#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int v;

vector<P> Num;

int main()
{
   scanf("%d",&v);
   int MIN = 1e9;
   for(int i = 1; i <= 9; i++){
       int x;
       scanf("%d",&x);
       Num.push_back(P(i,x));
       MIN = min(MIN,x);
   }
   string s;
   int ans = -1;
   while(v >= MIN){
      int len = v/MIN;
      for(int i = 8; i >= 0; i--){
         if(v >= Num[i].second && (v-Num[i].second)/MIN+1 == len){
            s.push_back(Num[i].first+48);
            v -= Num[i].second;
            break;
         }
      }
   }
   if(!s.empty()){
        cout << s << endl;
   }
   else cout << "-1" << endl;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值