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;
}