CF# Educational Codeforces Round 3 A. USB Flash Drives
2 seconds
256 megabytes
standard input
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.
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.
3
5
2
1
3
2
3
6
2
3
2
3
2
5
5
10
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.
除法
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int n, m, arr[N]; inline void Input()
{
scanf("%d", &n);
scanf("%d", &m);
for(int i = ; i < n; i++) scanf("%d", &arr[i]);
} inline void Solve()
{
sort(arr, arr + n, greater<int>());
int ans = , cnt = ;
for(int i = ; i < n; i++)
{
if(cnt >= m) break;
ans++, cnt += arr[i];
} cout << ans << endl;
} int main()
{
freopen("a.in", "r", stdin);
Input();
Solve();
return ;
}
CF# Educational Codeforces Round 3 A. USB Flash Drives的更多相关文章
- 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 ...
- CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组
题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点 ...
- CF Educational Codeforces Round 3 E. Minimum spanning tree for each edge 最小生成树变种
题目链接:http://codeforces.com/problemset/problem/609/E 大致就是有一棵树,对于每一条边,询问包含这条边,最小的一个生成树的权值. 做法就是先求一次最小生 ...
- CF# Educational Codeforces Round 3 F. Frogs and mosquitoes
F. Frogs and mosquitoes time limit per test 2 seconds memory limit per test 512 megabytes input stan ...
- CF# Educational Codeforces Round 3 E. Minimum spanning tree for each edge
E. Minimum spanning tree for each edge time limit per test 2 seconds memory limit per test 256 megab ...
- CF# Educational Codeforces Round 3 D. Gadgets for dollars and pounds
D. Gadgets for dollars and pounds time limit per test 2 seconds memory limit per test 256 megabytes ...
- CF# Educational Codeforces Round 3 C. Load Balancing
C. Load Balancing time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- CF# Educational Codeforces Round 3 B. The Best Gift
B. The Best Gift time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- CF Educational Codeforces Round 57划水记
因为是unrated于是就叫划水记了,而且本场也就用了1h左右. A.B:划水去了,没做 C:大水题,根据初三课本中圆的知识,可以把角度化成弧长,而这是正多边形,所以又可以化成边数,于是假设读入为a, ...
随机推荐
- 解决eclipseMavne的web项目debug时没有源码
- eclipse maven tomcat7 热部署
.配置tomcat a.配置jdk b.CATALINA_HOME=c:\tomcat CATALINA_BASE=c:\tomcat .tomcat配置密码 C:\Program Files\oth ...
- 10.11 cocoapods安装
手动安装gem 手动下载 rubygem https://rubygems.org/pages/download#formats 10.11 cocoapods安装 sudo gem install ...
- class-dump获取iOS私有api
转自:http://blog.csdn.net/sunyuanyang625/article/details/41440167 获取各类iOS私有api 安装工具class-dump 资源地址http ...
- NYOJ题目889求距离
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsYAAAJ2CAIAAADTwNOXAAAgAElEQVR4nO3dPVLrSteG4W8S5B4IsQ
- 深入理解SELinux SEAndroid
参考文章: 一. http://blog.csdn.net/innost/article/details/19299937 二. http://blog.csdn.net/innost/article ...
- Delphi之DLL知识学习5---在Delphi应用程序中使用DLL
首先说明一下:同一个动态库(DLL)被多个的程序加载的话,那么将会在每次加载的时候都会重新分配新的独立的内存空间,绝对不是共用一个,所以当一个DLL被多次加载的时候,其会在内存中“复制”多份,不会互相 ...
- Delphi面向对象---接口
从Delphi3开始支持接口.接口定义了能够与一个对象进行交互操作的一组过程和函数.对一个接口进行定义包含两个方面的内容: 1)一方面是实现这个接口 2)另一方面是定义接口的客户 一个类能够实现多个接 ...
- protobuf-net 对象二进制序列化与反序列号(转)
概述: Protobuf是google开源的一个项目,用户数据序列化反序列化,google声称google的数据通信都是用该序列化方法.它比xml格式要少的多,甚至比二进制数据格式也小的多. Prot ...
- ytu 2558: 游起来吧!超妹!(水题,趣味数学题)
2558: 游起来吧!超妹! Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 7 Solved: 3[Submit][Status][Web Board ...