CF# Educational Codeforces Round 3 A. USB Flash Drives

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.

 

除法

 1 /**
 2 Create By yzx - stupidboy
 3 */
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <cstdlib>
 7 #include <cmath>
 8 #include <deque>
 9 #include <vector>
10 #include <queue>
11 #include <iostream>
12 #include <algorithm>
13 #include <map>
14 #include <set>
15 #include <ctime>
16 #include <iomanip>
17 using namespace std;
18 typedef long long LL;
19 typedef double DB;
20 #define MIT (2147483647)
21 #define INF (1000000001)
22 #define MLL (1000000000000000001LL)
23 #define sz(x) ((int) (x).size())
24 #define clr(x, y) memset(x, y, sizeof(x))
25 #define puf push_front
26 #define pub push_back
27 #define pof pop_front
28 #define pob pop_back
29 #define mk make_pair
30 
31 inline int Getint()
32 {
33     int Ret = 0;
34     char Ch = ' ';
35     bool Flag = 0;
36     while(!(Ch >= '0' && Ch <= '9'))
37     {
38         if(Ch == '-') Flag ^= 1;
39         Ch = getchar();
40     }
41     while(Ch >= '0' && Ch <= '9')
42     {
43         Ret = Ret * 10 + Ch - '0';
44         Ch = getchar();
45     }
46     return Flag ? -Ret : Ret;
47 }
48 
49 const int N = 110;
50 int n, m, arr[N];
51 
52 inline void Input()
53 {
54     scanf("%d", &n);
55     scanf("%d", &m);
56     for(int i = 0; i < n; i++) scanf("%d", &arr[i]);
57 }
58 
59 inline void Solve()
60 {
61     sort(arr, arr + n, greater<int>());
62     int ans = 0, cnt = 0;
63     for(int i = 0; i < n; i++)
64     {
65         if(cnt >= m) break;
66         ans++, cnt += arr[i];
67     }
68     
69     cout << ans << endl;
70 }
71 
72 int main()
73 {
74     freopen("a.in", "r", stdin);
75     Input();
76     Solve();
77     return 0;
78 }
View Code

 

posted @ 2015-12-22 21:45  yanzx6  阅读(247)  评论(0编辑  收藏  举报