题目1436:Repair the Wall
来源:互联网 发布:网络机柜装置 编辑:程序博客网 时间:2024/06/07 23:52
#include<stdio.h>#include<algorithm>using namespace std;int main(){ long L;int N; while(scanf("%ld%d",&L,&N)!=EOF) { int i,a[601]; for(i=0;i<N;i++) { scanf("%d",&a[i]); } sort(a,a+N); bool flag=false; long sum=0;int ans=0; for(i=N-1;i>=0;i--) { if(sum+a[i]<=L) { sum+=a[i]; ans++; if(sum==L) { flag=true; break; } } else {ans++;flag=true; break;} } if(flag==true) { printf("%d\n",ans); } if(flag==false) printf("impossible\n"); } return 0;}/************************************************************** Problem: 1436 User: cust123 Language: C++ Result: Accepted Time:10 ms Memory:1020 kb****************************************************************/
0 0
- 题目1436:Repair the Wall
- 题目1436:Repair the Wall
- 题目1436:Repair the Wall
- 题目1436:Repair the Wall
- 题目1436:Repair the Wall
- 九度题目1436:Repair the Wall
- 九度 题目1436:Repair the Wall
- 24-题目1436:Repair the Wall
- 题目24:Repair the Wall
- 题目24:Repair the Wall
- 题目1436:Repair the Wall 九度OJ
- 九度考研机试教程 24-题目1436:Repair the Wall
- 九度OJ-1436-Repair the Wall
- hdu2124 Repair the Wall
- Repair the Wall+贪心
- Repair the Wall
- 2124:Repair the Wall
- Repair the Wall
- 第一章 51单片机环境的搭建-1.1 由点亮一个LED引入
- 动态内存分配_c语言学习笔记
- C5-1 “鱼额宝”
- Android项目实践--《智慧校园》
- 手动向Maven本地仓库添加ORACLE jdbc驱动
- 题目1436:Repair the Wall
- 从web实时通信讲H5 WebSocket
- Java 内存管理白皮书,读完它,java 内存管理的问题完全 NO Problem!
- 事务
- 文章标题
- There is no getter for property named 'insurance_id' in 'class studio.geek.entity.StudentInsurance'
- android压缩代码和资源
- linux notepadqq不支持中文输入的原因分析
- 前端面试经历及总结