A. 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.

Sample test(s)
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.

贪心,这个没什么好说的,拿大的放进去就好

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int i,j;
int t;
int n,m;
int a[1000000];
int main()
{
int sum=0;
int num=1;
cin>>n>>m;
for(i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
for(i=n-1;i>=0;i--)
{
sum+=a[i];
if(sum>=m)
{
break;
}
}
cout<<n-i<<endl;
return 0;
}

  

Educational Codeforces Round 3 A的更多相关文章

  1. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  2. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  3. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  4. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  5. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  6. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  7. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  8. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  10. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

随机推荐

  1. Yaffs2根文件系统制作

    Yaffs2根文件系统制作 环境: 交叉编译环境:4.4.6 开发平台:s3c2416 1,编译busybox 获取busybox源码busybox-1.17.2.tar (http://www.bu ...

  2. android opencv

    最近工作需求:用opencv来先做一个demo.扫描照片进行边缘检测和透视矫正. 之后会加入照片降噪等处理. 请教了一下搞图像的同事.他的提议: 1.绿盟的“黄色照片检测” 用的是动态的opencv库 ...

  3. Oracle pl/sql 基础入门语法

    PL/SQL是一种块结构的语言,这意味着PL/SQL程序被划分和编写代码的逻辑块.每块由三个子部分组成:1     声明 此部分开头使用关键字DECLARE.它是一个可选的部分,并限定在该程序中使用的 ...

  4. for xml path 按分类合并行数据

    ) as itemnum FROM ( SELECT Sonum, (SELECT ItemNum+',' FROM testtb    WHERE Sonum=A.Sonum    FOR XML  ...

  5. 使用jar打war包或解压war包

    进入Dos命令行,并到目标文件夹,如C:\Temp,待打包的内容在C:\Temp\Blog里,目标,把Blog里的相应文件打成war报 1.打包 C:\Temp\jar -cvf Blog.war . ...

  6. Verilog 语言 001 --- 入门级 --- 编写一个半加器电路模块

    Verilog 语言编写一个 半加器 电路模块 半加器 的电路结构: S = A 异或 B C = A 与 B 1. 程序代码 module h_adder (A, B, SO, CO); input ...

  7. python 获取路径不同方法的比较

    在软件中经常需要获取文件所在路径,方法有很多种( 例如 os.path.realpath(__file__), os.getcwd(), os.path.abspath(__file__),  sys ...

  8. Java50道经典习题-程序24 根据输入求输出

    题目:给一个不多于5位的正整数,要求:一.求它是几位数,二.逆序打印出各位数字.分析: (1)利用随机函数产生[1,99999]之间的一个正整数n (2)将n转换成字符串s,调用字符串的length( ...

  9. BCP导入导出

  10. winform GDI基础(二)画带圆角的矩形框

    private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.SmoothingMode ...