A. USB Flash Drives
来源:互联网 发布:pfm软件 编辑:程序博客网 时间:2024/05/20 15:12
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, ..., anmegabytes. 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.
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.
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
35213
2
36232
3
25510
1
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.
解题说明:水题,排序然后用贪心即可。
#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>using namespace std;int main(){int n,m,a[103],i,cnt;cin >> n >> m;for(i=0;i<n;i++){cin >> a[i];}sort(a,a+n);i=n-1;cnt=0;while(m>0){m=m-a[i--];cnt++;}cout << cnt<<endl;return 0;}
- A. USB Flash Drives
- Codeforces 609A USB Flash Drives 【水题】
- CodeForces 609A USB Flash Drives
- CF 609A USB Flash Drives
- USB Flash Drives
- USB Flash Drives
- USB Flash Drives
- CodeForces 609 A. USB Flash Drives(贪心)
- Usb Flash Drives - backtrack 5
- USB Flash Drives(水题,排序)
- 【Educational Codeforces Round 3 A】【水题 排序】USB Flash Drives 最少数量U盘存储m大小文件
- 2017寒假集训-小题训练1:D - USB Flash Drives
- ivman does not mount usb hard drives
- How to disable USB Drives 如何禁用USB优盘
- Create bootable USB drives 制作iso转usb的启动盘
- Install Ubuntu 10.04 LTS on a USB Flash Memory
- Install CentOS 5 to a USB Flash Drive in Windows
- How to Configure Hard Disk Drives on a CEPC
- mongodb与sql聚合操作对应图
- mysql sql语句大全
- 高仿网易评论列表效果之界面生成(三)
- 在SPRING DATA MONGODB中使用聚合统计查询(Java)
- poj--3169--Layout(简单差分约束)
- A. USB Flash Drives
- 访问修饰符
- MySQL查看表占用空间大小
- MFC中打开 对话框中格式过滤的格式
- [笔记]Writing your first Django app
- String类
- java读取视频文件长
- linux防火墙设置
- Win10下使用PHP7+XDebug+Sublime Text 3搭建PHP集成开发环境