Tasks

It's too late now, but you still have too much work to do. There are nn tasks on your list. The ii-th task costs you t_iti​seconds. You want to go to bed TT seconds later. During the TT seconds, you can choose some tasks to do in order to finish as many tasks as possible.

Input

Each test file contains a single test case. In each test file:

There are only two lines. The first line contains two positive integers n ( n \le 100 )n(n≤100) and T ( T \le 6000 )T(T≤6000). The second line contains nn positive integers t_1t1​, t_2, \cdots , t_n ( t_i \le 100 )t2​,⋯,tn​(ti​≤100).

Output

A number representing how many tasks can you finish before going to bed if you make the optimal decision.

样例输入复制

5 10
8 3 4 2 1

样例输出复制

4

代码:

 //A-签到
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+; int a[maxn]; int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
sort(a+,a++n);
int cnt=,num=;
for(int i=;i<=n;i++){
if(cnt>=k){
printf("%d\n",num);
return ;
}
if(cnt+a[i]<=k){
cnt+=a[i];num++;
}
}
printf("%d\n",num);
}
05-11 22:13