贪心。

从大到小排序之后进行模拟,注意$n=1$和$n=0$的情况。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
using namespace std; int n,m;
int a[100010]; bool cmp(int x,int y)
{
return x>y;
} int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++) scanf("%d",&a[i]); sort(a+1,a+1+m,cmp); int now = n; if(n==0||n==1)
{
printf("0\n");
return 0;
} for(int i=1;i<=m;i++)
{
if(a[i] <= 0) break;
if(a[i]<now)
{
now = now - a[i];
a[i+1]--;
}
else
{
now = 0;
printf("%d\n",i);
break;
}
} if(now!=0)
{
printf("Impossible\n");
} return 0;
}

最新文章

  1. CSS 使用母版页的内容页如何调用css和javascript
  2. MySQL的特点
  3. eclipse启动时报错 Could not create the java virtual machine
  4. Swift开发小技巧--private访问修饰符报错的情况
  5. 纸上谈兵:哈希表(hash table)
  6. Android开发之 Android应用程序目录结构解析
  7. JQuery下CheckBox全选全不选反选
  8. iOS应用架构谈 本地持久化方案及动态部署
  9. Google Java Style Guide
  10. 转载Expression Tree揭秘
  11. linux shell 远程执行命令
  12. h5开发app之在线生成二维码
  13. 一个基于JRTPLIB的轻量级RTSP客户端(myRTSPClient)——解码篇:(一)用ffmpeg解码视频
  14. Android源码浅析(一)——VMware Workstation Pro和Ubuntu Kylin 16.04 LTS安装配置
  15. C语言之linux内核--BCD码转二进制与二进制转BCD码(笔试经典)
  16. MT【241】红蓝两色染色
  17. Toy Train(贪心)
  18. App调试的几个命令实践【转】
  19. django基础 -- 1. 前奏 web框架的本质
  20. 使用zabbix-java-gateway可以通过该网关来监听多个JVM

热门文章

  1. nova-conductor与AMQP(一)
  2. codeblocks 设置代码自动补全
  3. react UI组件库 Salt UI
  4. 使用FormData提交表单及上传文件
  5. 机器学习-kNN-数据归一化
  6. vs2012 error c4996: &#39;fopen&#39;: This function or variable may be unsafe
  7. vim 颜色主题设置
  8. ThinkPHP的运行流程-2
  9. 135.Candy---贪心
  10. beego学习笔记(4):开发文档阅读(5)