(CodeForces
来源:互联网 发布:c 程序员招聘 编辑:程序博客网 时间:2024/06/06 07:31
(CodeForces - 609A)USB Flash Drives
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, …, an megabytes. The file size is equal to m megabytes.
Find the minimum number of USB flash drives needed to write Sean’s file, if he can split the file between drives.
Input
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives.
The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean’s file.
Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all ai is not less than m.
Output
Print the minimum number of USB flash drives to write Sean’s file, if he can split the file between drives.
Examples
Input
3
5
2
1
3
Output
2
Input
3
6
2
3
2
Output
3
Input
2
5
5
10
Output
1
Note
In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
题目大意:有n个USB,每个USB可以存放a[i]字节数的文件,现在需要存放m字节的文件,问最少需要最少个USB。
思路:肯定是容量大的USB先装,然后在装小的,一直到装够m为止。
#include<cstdio>#include<algorithm>using namespace std;const int maxn=105;int a[maxn];bool cmp(int a,int b){ return a>b;}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { for(int i=0;i<n;i++) scanf("%d",a+i); sort(a,a+n,cmp); int ans,sum=0; for(int i=0;i<n;i++) { sum+=a[i]; if(sum>=m) { ans=i+1; break; } } printf("%d\n",ans); } return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 【正则表达式】
- MySQL中删除重复数据只保留一条
- noSQL DB 技术选型
- java的final变量浅析
- YAML 语言教程
- (CodeForces
- ssm 微信扫码支付
- SpringBoot系列
- Java面试宝典
- 机器学习xgboost实战—手写数字识别 (DMatrix)
- Java初学者问题图解_动力节点Java学院整理
- SpringMVC异常处理
- 【Java】try-catch-finally语句中return的执行顺序思考
- 新版支付宝支付