zcmu 1694: USB Flash Drives

1694: USB Flash Drives

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 350  Solved: 175
[Submit][Status][Web Board]

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

快淹死了~ 

 不用while 还wa了

tui~

#include<bits/stdc++.h>
#define ll long long
#define ve vector
#define mp map
#define NO cout<<"NO"<<endl;
#define YES cout<<"YES"<<endl;
#define pre(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,b,a) for(int i=b;i>=a;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define st string
#define N 10005
using namespace std;
const int maxn=1e6+5;
const ll mod =1e15;
const int dx[]={-1,0,1,0};
const int dy[]={0,1,0,-1};
//set<ll> s;
ve<ll> v;
priority_queue<ll, ve<ll>, greater<ll> >q;


int a[101];

int main(){
    int n,m;
    while(cin>>n>>m){
    int ans=0,tal=0;
    pre(i,1,n)cin>>a[i];
    sort(a+1,a+n+1);
    rep(i,n,1){
    	ans++;
    	tal+=a[i];
    	if(tal>=m){
	    cout<<ans<<endl;break;
	    }
    }
    mem(a,0);
    }
    return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值