zoukankan      html  css  js  c++  java
  • 计蒜客 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 }
  • 相关阅读:
    剑指offer十二之数值的整数次方
    剑指offer十一之二进制中1的个数
    剑指offer十之矩形覆盖
    剑指offer九之变态跳台阶
    剑指offer八之跳台阶
    程序员的生活观
    程序员,如何远离你的电脑
    生活管理实用技能
    分享共筑 : 伟大的理念
    技术人员,要学会关心别人
  • 原文地址:https://www.cnblogs.com/ZERO-/p/11283254.html
Copyright © 2011-2022 走看看