Description

Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful. The only thing that troubled her is the typhoon.

When the typhoon came, everything is terrible. It kept blowing and raining for a long time. And what made the situation worse was that all of Kitty's walls were made of wood.

One day, Kitty found that there was a crack in the wall. The shape of the crack is 
a rectangle with the size of 1×L (in inch). Luckly Kitty got N blocks and a saw(锯子) from her neighbors. 
The shape of the blocks were rectangle too, and the width of all blocks were 1 inch. So, with the help of saw, Kitty could cut down some of the blocks(of course she could use it directly without cutting) and put them in the crack, and the wall may be repaired perfectly, without any gap.

Now, Kitty knew the size of each blocks, and wanted to use as fewer as possible of the blocks to repair the wall, could you help her ?

 

Input

The problem contains many test cases, please process to the end of file( EOF ). 
Each test case contains two lines. 
In the first line, there are two integers L(0<L<1000000000) and N(0<=N<600) which 
mentioned above. 
In the second line, there are N positive integers. The i th integer Ai(0<Ai<1000000000 ) means that the i th block has the size of 1×Ai (in inch). 
 

Output

For each test case , print an integer which represents the minimal number of blocks are needed. 
If Kitty could not repair the wall, just print "impossible" instead. 
 

Sample Input

5 3
3 2 1
5 2
2 1
 

Sample Output

2
impossible
 
 #include<cstdio>
#include<algorithm>
using namespace std;
int a[];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int m,n,i,j;
int sum;
while(scanf("%d %d",&m,&n)!=EOF)
{
sum=;
j=;
for(i=; i < n; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n,cmp);
for(i=;i<n;i++)
{
sum+=;
m-=a[i];
if(m <= )
{
j=-;
printf("%d\n",sum);
break;
}
}
if(j == ) printf("impossible\n");
}
}

杭电 2124 Repair the Wall(贪心)的更多相关文章

  1. --hdu 2124 Repair the Wall(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2124 Ac code : #include<stdio.h> #include<st ...

  2. HDU 2124 Repair the Wall

    http://acm.hdu.edu.cn/showproblem.php?pid=2124 Problem Description Long time ago , Kitty lived in a ...

  3. 杭电 2111 Saving HDU (贪心)

    Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏的商人,XHD不会坐以待毙的.   一天,当他正在苦思冥想解困良策的时候,突然想到了自己 ...

  4. 杭电 1009 FatMouse' Trade (贪心)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  5. 简单贪心) Repair the Wall hdu2124

    Repair the Wall http://acm.hdu.edu.cn/showproblem.php?pid=2124 Time Limit: 5000/1000 MS (Java/Others ...

  6. 杭电OJ1789、南阳OJ236(贪心法)解题报告

    杭电OJ1789http://acm.hdu.edu.cn/showproblem.php?pid=1789 南阳OJ236http://59.69.128.203/JudgeOnline/probl ...

  7. Repair the Wall (贪心)

    Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful ...

  8. HDU2124 Repair the Wall(贪心)

    Problem Description Long time ago , Kitty lived in a small village. The air was fresh and the scener ...

  9. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

随机推荐

  1. 深入浅出索引--Mysql45讲笔记记录 打卡day3

    看了极客时间的mysql45讲记录一下自己理解的关于索引部分 为什么会有索引呢? 答:索引就像书的目录一样,可以让你快速知道你要看的部分在多少页.换句话说,索引就是为了提高数据库的查询效率. 索引的数 ...

  2. 团队作业-项目Alpha版本发布

    一. 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 这个作业要求在哪里 https://edu.cn ...

  3. 题解报告:hdu 1159 Common Subsequence(最长公共子序列LCS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Problem Description 给定序列的子序列是给定的序列,其中有一些元素(可能没有) ...

  4. 转】在Ubuntu中安装Cassandra

    原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/ 感谢! Posted: Mar 22, 2014 Tags: cas ...

  5. node入门(一)——安装

    node可以让我们用js写服务器.此外还可以用来前端自动化开发,它找到特定服务要使用的包,然后下载.安装.管理. 首先安装node,进入官网下载需要的node版本,然后一键式傻瓜安装.(我的环境是wi ...

  6. 【原】无脑操作:Eclipse + Maven + jFinal + MariaDB 环境搭建

    一.开发环境 1.windows 7 企业版 2.Eclipse IDE for Enterprise Java Developers  Version: 2019-03 (4.11.0) 3.JDK ...

  7. AJPFX总结泛型概念和使用

    泛型泛型(generic)概述和基本使用                泛型把明确数据类型的操作放到创建对象或者调用方法的时候再明确.                                J ...

  8. 2019最新Android面试题

    原文链接:https://blog.csdn.net/wen_haha/article/details/88362469版权声明:本文为博主原创文章,转载请附上博文链接! 前言 金三银四到来了,找工作 ...

  9. C#代码规范(简版)

    C#项目代码规范 目的 1.方便代码的交流和维护. 2.不影响编码的效率,不与大众习惯冲突. 3.使代码更美观.阅读更方便. 4.使代码的逻辑更清晰.更易于理解. 在C#中通常使用的两种编码方式如下 ...

  10. 使用 ArrayAdapter 来定制 ListView

    一个 ListView,其宽高都设为 match_parent,可以更省资源. activity_main.xml <ListView android:id="@+id/list_Vi ...