Color the Fence

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

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 Input

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个数字,写每个数字都耗费不同的燃料,问你用这些燃料最多能写出来的数字是多少 #感悟:爆炸,尽然没想起来这么贪,最长的长度肯定cur=v/minv然后,枚举cur位,都尽可能的取一个最大的数 */ #include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int a[];
vector<int> v;
int n;
int minv=INF;
int mini;
int cur;
int main(){
// freopen("in.txt","r",stdin);
v.clear();
scanf("%d",&n);
for(int i=;i<;i++){
scanf("%d",&a[i]);
if(a[i]<=minv){
minv=a[i];
mini=i;
}
}
cur=n/minv;
if(cur==){
puts("-1");
return ;
}
int res=;
for(int i=;i<cur;i++){//查找每一位
for(int j=;j>=;j--){
//每一位都找最大的
if(n<=minv){
v.push_back(mini+);
break;
}
if(a[j]>n) continue;
if( (n-a[j])/minv+v.size()+==cur){
res+=a[j];
v.push_back(j+);
n-=a[j];
break;
}
}
}
for(int i=;i<v.size();i++){
printf("%d",v[i]);
}
printf("\n");
return ;
}

349B - Color the Fence的更多相关文章

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

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

  2. Codeforces 349B - Color the Fence

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

  3. 【贪心】Codeforces 349B.Color the Fence题解

    题目链接:http://codeforces.com/problemset/problem/349/B 题目大意 小明要从9个数字(1,2,--,9)去除一些数字拼接成一个数字,是的这个数字最大. 但 ...

  4. CodeForces 349B Color the Fence (DP)

    题意:给出1~9数字对应的费用以及一定的费用,让你输出所选的数字所能组合出的最大的数值. 析:DP,和01背包差不多的,dp[i] 表示费用最大为 i 时,最多多少位,然后再用两个数组,一个记录路径, ...

  5. ACM Color the fence

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

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

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

  7. nyoj Color the fence

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

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

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

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

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

随机推荐

  1. angular-bootstrap ui-date组件问题总结

    使用angular框架的时候,之前用的时间控件是引入My97DatePicker组件实现的,但是因为 1.My97DatePicker样式不太好看以及偶尔会出现底部被遮盖的情况.点击不可编辑input ...

  2. jquery对象和js对象

    <ul id="ul1">   <li id="li_1">01</li>   <li>02</li> ...

  3. webstorm配置scss环境

    1.下载 Ruby  (安装过程中记得勾选添加到环境变量,安装结束最后可能会弹出一个cmd弹框,可以忽略) 2. cmd安装sass gem install sass 3. cmd检查是否安装 sas ...

  4. Python CSV 超简明用法

    平常经常会用CSV存储数据,不可避免的会跟CSV文件的读写操作扯上关系. Python有CSV这个Package来解决这个问题,官网也有比较详细的教程 https://docs.python.org/ ...

  5. 初学node.js有感三

    WebStorm下的node.js 一.回顾与继续       在前面,我们知道了node.js的基本框架和思路,在这些原生环境下我们对node.js的设计思想有了比较深刻的认识,并且具有了编写大型程 ...

  6. SpringMVC学习笔记(二)

    一.导航 复杂类型的参数绑定 校验 异常处理 图片上传 json交互 拦截器 二.复杂类型参数绑定 ①.包装类型的pojo参数绑定 使用场景:实现商品查询条件传入. 实现方法:>通过添加Http ...

  7. 大牛教你用3行HTML代码卡死一台机器

    前言 学习web渗透测试等安全工作的朋友们,想必大部分接触的最早的就是HTML了. 其实学过html的朋友们都知道,html中可以插入JavaScript代码,而对于JavaScript代码,这里就不 ...

  8. JavaWeb(四)EL表达式

    前言 前面详细的说明了什么是JSP和它的一些元素,这篇给大家介绍一下的是EL表达式. 用EL表达式,能更好的使用JSP中的各种内置对象和作用域. 楼主作为大四狗马上要出去面试了,内心很紧张!!! 一. ...

  9. gitlab仓库迁移

    遇到一个情况,需要将两个gitlab仓库合并.好在都是使用的ldap账户登陆,用户账户不需要迁移. 实际的使用情况下,需要迁移的主要部分为分组及分组下项目.gitlab的api还是很给力的,能够获取所 ...

  10. 从实践的角度理解cookie的几个属性

    cookie的处理流程大致分为以下几步: 1.浏览器初次请求服务器. 2.服务器认为有必要设置cookie,通过响应报文首部:Set-Cookie告知浏览器,cookie的内容. 3.浏览器本地保存( ...