• 计蒜客 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
    ",num);
    21             return 0;
    22         }
    23         if(cnt+a[i]<=k){
    24             cnt+=a[i];num++;
    25         }
    26     }
    27     printf("%d
    ",num);
    28 }
  • 相关阅读:
    Strus2第一次课:dom4j操作xml
    Strus2第一次课:dom4j解析xml文档
    2014最后一天,好烦!这个问题从来没遇到过!网上查找了很多办法都没解决!并且no wifi 了!
    MyBatis 入门(一)
    RSA学习记录
    [HCTF 2018]admin学习记录
    [HDCTF2019]together
    BUUCTF刷题记录REAL类
    BUUCTF刷题记录————unencode
    实验四
  • 原文地址:https://www.cnblogs.com/ZERO-/p/11283254.html
Copyright © 2020-2023  润新知