计蒜客 39268.Tasks-签到 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest A.) 2019ICPC西安邀请赛...

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_itiseconds. 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(n100) and T ( T \le 6000 )T(T6000). The second line contains nn positive integers t_1t1t_2, \cdots , t_n ( t_i \le 100 )t2,,tn(ti100).

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

 

 

代码:

 1 //A-签到
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 typedef long long ll;
 5 const int maxn=1e5+10;
 6 
 7 int a[maxn];
 8 
 9 int main()
10 {
11     int n,k;
12     scanf("%d%d",&n,&k);
13     for(int i=1;i<=n;i++){
14         scanf("%d",&a[i]);
15     }
16     sort(a+1,a+1+n);
17     int cnt=0,num=0;
18     for(int i=1;i<=n;i++){
19         if(cnt>=k){
20             printf("%d\n",num);
21             return 0;
22         }
23         if(cnt+a[i]<=k){
24             cnt+=a[i];num++;
25         }
26     }
27     printf("%d\n",num);
28 }

 

转载于:https://www.cnblogs.com/ZERO-/p/11283254.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值