Codeforces Educational Codeforces Round 3 A. USB Flash Drives 水题
A. USB Flash Drives
题目连接:
http://www.codeforces.com/contest/609/problem/A
Description
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.
Sample Input
3
5
2
1
3
Sample Output
2
Hint
题意
给你n个u盘,每个u盘的容量为a[i],给你一个M大小的文件,问你最少用多少个U盘就可以装完。
题解:
贪心。将U盘按照从大到小排序,然后依次装进U盘,知道M大小被装完。
代码
#include<bits/stdc++.h>
using namespace std;
int a[105];
bool cmp(int A,int B)
{
return A>B;
}
int main()
{
int n;scanf("%d",&n);
int m;scanf("%d",&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n,cmp);
int ans = 0;
for(int i=1;i<=n;i++)
{
m-=a[i];
ans++;
if(m<=0)break;
}
printf("%d\n",ans);
}
Codeforces Educational Codeforces Round 3 A. USB Flash Drives 水题的更多相关文章
- CF# Educational Codeforces Round 3 A. USB Flash Drives
A. USB Flash Drives time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- Codeforces Educational Codeforces Round 15 D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Educational Codeforces Round 14 A. Fashion in Berland 水题
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
- codeforces Educational Codeforces Round 24 (A~F)
题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Codeforces Beta Round #14 (Div. 2) A. Letter 水题
A. Letter 题目连接: http://www.codeforces.com/contest/14/problem/A Description A boy Bob likes to draw. ...
随机推荐
- PHP QR CODE生成二维码
用法: <?php include "./phpqrcode/phpqrcode.php"; $value="http://www.xxx.com"; $ ...
- go 应用程序性能测试
runtime/pprof 我们要加入对pprof包里的方法调用,程序才能将运行时候程序的堆内存分配状态记录到文件(也可以是写到其他地方,例如网络等)中,以便进一步的分析. 如果你的go程序只是一个应 ...
- LoadRunner--内存指标介绍
Threads——线程数当前全部线程数============================================ Available MBytes——物理内存的可用数指计算机上可用于运行 ...
- dzzoffice应用如何安装
在dzz应用市场中,进入到每个应用的详细介绍页面.里面有对于每个应用或者主题的安装说明. dzz应用市场:http://dev.dzzoffice.com/index.php?mod=dzzmarke ...
- 华丽的bootstrap3碰到土鳖IE6
之前由于看好很容易上手的bootstrap,然后用这个框架写了个网站,对于不会美工和细致设计的攻城师来说,bootstrap是个界面设计的瑞士军刀,三下五除二就能搞定个不算太丑的页面. 吭哧吭哧工作了 ...
- 【LeetCode】36 - Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.(http://sudoku.com.au/TheRu ...
- 禁止Windows安装软件
今天电脑莫名安装上百度杀毒,想永久解决这个问题. 1.卸载百度杀毒 2.运行cmd-->sc delete 'service name' 3.sc delete BDMiniDlUpdate/B ...
- To follow the path
look to the master, follow the master, walk with the master, see through the master, bec ...
- RFID之UID
1 Unique identifier (UID) The VICCs are uniquely identified by a 64 bits unique identifier (UID). Th ...
- C++的引用类型的变量到底占不占用内存空间?
——by karottc 分析一下 C++ 里面的引用类型(例如: int &r = a; )中的 r 变量是否占用内存空间呢?是否和 int *p = &a; 中的 p 变量 ...