(比赛)B

B - Super Mobile Charger

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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

2
3 10
100 99 90
3 1000
0 0 0

Sample Output

2
3


//很水的题目,好像是贪心吧
没有坑点,但是,无语的是第一二次提交 wa ,很崩溃,随便改了下。第三次过了,然后我去找哪里错了,结果复制了一模一样的,ac 了,真他妈碰鬼了
0 ms
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 int ph[102];
 7 
 8 int cmp(int a,int b)
 9 {
10     return a>b;
11 }
12 
13 int main()
14 {
15     int T;
16     int i,n,k,m;
17     scanf("%d",&T);
18     while(T--)
19     {
20         scanf("%d%d",&n,&m);
21         for (i=0;i<n;i++)
22             scanf("%d",&ph[i]);
23         sort(ph,ph+n,cmp);
24         for (i=0;i<n;i++)
25         {
26             if (m<100-ph[i])
27                 break;
28             m-=100-ph[i];
29         }
30         printf("%d
",i);
31     }
32     return 0;
33 }
View Code
 
原文地址:https://www.cnblogs.com/haoabcd2010/p/5766077.html