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. ...
随机推荐
- spring实例化bean的方式
1.使用类构造器实现实例化(bean的自身构造器) <bean id = "orderService" class="cn.itcast.OrderServiceB ...
- 大数据时代的数据存储,非关系型数据库MongoDB
在过去的很长一段时间中,关系型数据库(Relational Database Management System)一直是最主流的数据库解决方案,他运用真实世界中事物与关系来解释数据库中抽象的数据架构. ...
- linux c 多线程编程
linux 下 c 语言多线程: /* 06.3.6 Mhello1.c Hello,world -- Multile Thread */ #include<stdio.h> #inclu ...
- QS之vcom
-2008 | -2002 | -93 | -87 choose VHDL 2008, 2002, 1993, or 1987 -explicit resolve ambiguous overload ...
- JQuery Mobile移动Web应用开发(1): UI开发工具RID介绍
工欲善其事,必先利其器. UI工具可以提高我们开发界面的效率,下面对几款工具做个对比: 1. Codiqa,在JQuery Mobile主页能看到这款工具,看到网上这么多人吹捧这个工具,不过是收费的. ...
- QCon 2013 上海 -- 互联网金融
互联网金融应该是最近很火爆的一个领域.由于阿里小贷和余额宝的初步成功,这一块都被视为破除传统金融领域垄断的法宝.大家可能都知道,电商平台.金融和大数据是阿里集团未来的三个重要方面.而关于金融,马云最经 ...
- ubuntu 彻底删除软件包
找到此软件名称,然后sudo apt-get purge ......(点点为为程序名称),purge参数为彻底删除文件,然后sudo apt-get autoremove,sudo apt-get ...
- 解决getOutputStream() has already been called for this response
http://qify.iteye.com/blog/747842 —————————————————————————————————————————————————— getOutputStream ...
- CentOS(RedHat) 6.2 Samba share权限拒绝访问
在实现<CentOS(RedHat) 6.2下Samba配置>的过程中,发现CentOS 6.2的Samba share总是没有权限写文件,已经试过在Windows XP/Windows ...
- Win7 SP1语言包微软官方下载地址及使用方法 2
情形一:如果您的系统版本是企业版.旗舰版,可以在Windows update中检测语言包按照提示下载安装即可.如果觉得Windows update不方便的话,可以在本文第二部分中下载所需的语言包,下载 ...