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

被这道题卡了蛮久,只考虑到了位数最大,没想到要尽可能小以给高位腾出更多空间。

附AC代码:

 #include<bits/stdc++.h>
using namespace std; int a[]; const int INF=<<; int main(){
int v,temp=;
int Max=;
int Min=INF;
cin>>v;
for(int i=;i<=;i++){
cin>>a[i];
if(v/a[i]>Max||a[temp]==a[i]){
Max=v/a[i];
temp=i;
}
if(a[i]<=Min){
Min=a[i];
}
}
if(Max==){
cout<<-<<endl;
return ;
}
else{
int num=v/a[temp]; Min=INF;
for(int i=temp+;i<=;i++){
if(a[i]<=Min){
Min=a[i];
}
}
v%=a[temp];
while(v>&&v+a[temp]>=Min){
int t;
for(int i=;i>temp;i--){
if(a[i]<=v+a[temp]){
cout<<i;
num--;
t=i;
break;
}
}
v-=abs(a[t]-a[temp]);
}
for(int i=;i<num;i++){
cout<<temp;
} cout<<endl;
}
return ;
}

B. Color the Fence的更多相关文章

  1. ACM Color the fence

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  2. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  3. NYOJ-791 Color the fence (贪心)

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  4. 349B - Color the Fence

    Color the Fence Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Su ...

  5. nyoj Color the fence

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  6. Codeforces 349B - Color the Fence

    349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio& ...

  7. nyoj 791——Color the fence——————【贪心】

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  8. Codeforces D. Color the Fence(贪心)

    题目描述: D. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. codeforces B. Color the Fence 解题报告

    题目链接:http://codeforces.com/problemset/problem/349/B 题目意思:给定v升的颜料和9个需要花费ad 升的颜料,花费ad 升的颜料意味着得到第d个数字,现 ...

随机推荐

  1. scapy在wlan中的应用

    Scapy 又是scapy,这是python的一个网络编程方面的库,它在wlan中也有很强大的应用.一般我们买块网卡,然后aircrack-ng套件爆破一下邻居的密码,其实我们可以用scapy写一些有 ...

  2. BUPT复试专题—旋转图像(2014)

    题目描述 将一幅只含有01像素点的图片进行顺时针旋转,旋转的角度仅包含0°,90°,180°,270° 输入 第一行一个整数T(<50)表示输入的组数 每组测试数据第一行是两个整数N和M(< ...

  3. ubuntu 14.04安装nodejs

    http://stackoverflow.com/questions/32902699/cannot-install-ember-on-ubuntu-1404/33495134

  4. Android 系统广播机制

    一.Android应用程序注冊广播接收器(registerReceiver)的过程分析 參考Android应用程序注冊广播接收器(registerReceiver)的过程分析http://blog.c ...

  5. hunnu--11545--小明的烦恼——找路径

    小明的烦恼--找路径  Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:32768KB Total submit users:  ...

  6. @SuppressWarnings 用法

    从Java 5.0起,您可以使用java.lang.SuppressWarning注释,来停用与编译单元子集相关的编译警告 作用:用于抑制编译器产生警告信息. Idea 设置泛型检查,变量.方法未使用 ...

  7. Apache Qpid CPP的编译与安装

    单机Broker部署(windows/linux) 在Windows/Linux上部署QPID Broker的方法. Windows 需要预先准备的文件和程序 qpid-cpp-0.32.tar.gz ...

  8. java学习方向及主要内容

    Java分成J2ME(移动应用开发),J2SE(桌面应用开发),J2EE(Web企业级应用),所以java并不是单机版的,只是面向对象语言.建议如果学习java体系的话可以这样去学习: *第一阶段:J ...

  9. using the flume-ng-sql-source plugin to push data from Mysql DB to Spark

    org.apache.flume.EventDeliveryException while running flume and sending data to spark · Issue #21 · ...

  10. 在C语言中使用libb64进行Base64编解码

    libb64下载地址http://sourceforge.net/projects/libb64 以下为Demo libb64_demo.c #include <stdio.h> #inc ...