Codeforces 609A USB Flash Drives 【水题】

来源:互联网 发布:thinkphp商城免费源码 编辑:程序博客网 时间:2024/05/20 11:22

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
35213
output
2
input
36232
output
3
input
25510
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.



题意:给你一个m大的总内存和n个USB快闪驱动器,问你至少需要多少个USB快闪驱动器才能装满或者超过总内存。


排下序,模拟就好了。


AC代码:


#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (100+10)#define MAXM (100000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;int a[MAXN];int main(){    int n, m;    Ri(n); Ri(m);    for(int i = 0; i < n; i++)        Ri(a[i]);    sort(a, a+n);    int ans = 0;    for(int i = n-1; i >= 0; i--)    {        ans++;        m -= a[i];        if(m <= 0)            break;    }    Pi(ans);    return 0;}


0 0
原创粉丝点击