A

来源:互联网 发布:2k18奥尼尔捏脸数据 编辑:程序博客网 时间:2024/05/16 16:12
A - 1001
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice FZU 2212

Description

While HIT ACM Group finished their contest in Shanghai and is heading back Harbin, their train was delayed due to the heavy snow. Their mobile phones are all running out of battery very quick. Luckily, zb has a super mobile charger that can charge all phones.

There are N people on the train, and the i-th phone has p[i] percentage of power, the super mobile charger can charge at most M percentage of power.

Now zb wants to know, at most how many phones can be charged to full power. (100 percent means full power.)

Input

The first line contains an integer T, meaning the number of the cases (1 <= T <= 50.).

For each test case, the first line contains two integers N, M(1 <= N <= 100,0 <= M <= 10000) , the second line contains N integers p[i](0 <= p[i] <= 100) meaning the percentage of power of the i-th phone.

Output

For each test case, output the answer of the question.

Sample Input

23 10100 99 903 10000 0 0

Sample Output

23

解题思路:
对输入的数据排序,让电池从电最多到电最少的手机开始充电

代码:

#include <iostream>#include<vector>#include<algorithm>#include<cstdio>#include<string>#include<map>using namespace std;int main(){    int n,i,t,m;    int a[105];    cin>>t;    while(t--)    {        cin>>n>>m;        for(i=0;i<n;i++)        cin>>a[i];        sort(a,a+n);        int num=0;        for(i=n-1;i>=0;i--)        {            if(a[i]==100) {num++; continue;}            else            {                if(m-(100-a[i])>=0) {m-=(100-a[i]); num++;}                else break;            }        }        cout<<num<<endl;    }    return 0;}


 

0 0
原创粉丝点击