博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Educational Codeforces Round 85 (Rated for Div. 2)B. Middle Class
阅读量:4034 次
发布时间:2019-05-24

本文共 2806 字,大约阅读时间需要 9 分钟。

Many years ago Berland was a small country where only n people lived. Each person had some savings: the i-th one had ai burles.

The government considered a person as wealthy if he had at least x burles. To increase the number of wealthy people Berland decided to carry out several reforms. Each reform looked like that:

the government chooses some subset of people (maybe all of them);

the government takes all savings from the chosen people and redistributes the savings among the chosen people equally.
For example, consider the savings as list [5,1,2,1]: if the government chose the 1-st and the 3-rd persons then it, at first, will take all 5+2=7 burles and after that will return 3.5 burles to the chosen people. As a result, the savings will become [3.5,1,3.5,1].

A lot of data was lost from that time, so we don’t know how many reforms were implemented and to whom. All we can do is ask you to calculate the maximum possible number of wealthy people after several (maybe zero) reforms.

Input

The first line contains single integer T (1≤T≤1000) — the number of test cases.

Next 2T lines contain the test cases — two lines per test case. The first line contains two integers n and x (1≤n≤105, 1≤x≤109) — the number of people and the minimum amount of money to be considered as wealthy.

The second line contains n integers a1,a2,…,an (1≤ai≤109) — the initial savings of each person.

It’s guaranteed that the total sum of n doesn’t exceed 105.

Output

Print T integers — one per test case. For each test case print the maximum possible number of wealthy people after several (maybe zero) reforms.

Example

inputCopy
4
4 3
5 1 2 1
4 10
11 9 11 9
2 5
4 3
3 7
9 4 9
outputCopy
2
4
0
3

Note

The first test case is described in the statement.

In the second test case, the government, for example, could carry out two reforms: [11–––,9–,11,9]→[10,10,11–––,9–]→[10,10,10,10].

In the third test case, the government couldn’t make even one person wealthy.

In the fourth test case, the government could choose all people to carry out a reform: [9–,4–,9–]→[713,713,713].

题意

有n个人,每个人都有一定数量的钱,选出一部分人来将他们的钱平分,问在评分后的钱大于x的情况下,最多能选多少人

思路

优先选钱多的,

本来就大于x的一定选,然后再优先选取钱较多的才能实现最大
具体实现见代码

代码:

#include
#include
#include
using namespace std;typedef long long ll;const int N = 1e5 + 10;int t;ll a[N];bool cmp(int x, int y){
return x > y;}int main() {
cin>>t; while (t--) {
ll n, x; cin>>n>>x; for (int i = 1; i <= n; ++i) cin>>a[i]; sort(a + 1, a + n + 1,cmp);//降序 ll sum = 0; int ans = 0; for (int i = 1; i <= n; ++i) //判断选取 {
sum += a[i]; if (sum < x * i) break; else ans++; } printf("%d\n", ans); }}

码字不易,留个赞吧~

转载地址:http://eafdi.baihongyu.com/

你可能感兴趣的文章
”舍得“大法:把自己的优点当缺点倒出去
查看>>
[今日关注]鼓吹“互联网泡沫,到底为了什么”
查看>>
[互联网学习]如何提高网站的GooglePR值
查看>>
[关注大学生]求职不可不知——怎样的大学生不受欢迎
查看>>
[关注大学生]读“贫困大学生的自白”
查看>>
[互联网关注]李开复教大学生回答如何学好编程
查看>>
[关注大学生]李开复给中国计算机系大学生的7点建议
查看>>
[关注大学生]大学毕业生择业:是当"鸡头"还是"凤尾"?
查看>>
[茶余饭后]10大毕业生必听得歌曲
查看>>
gdb调试命令的三种调试方式和简单命令介绍
查看>>
C++程序员的几种境界
查看>>
VC++ MFC SQL ADO数据库访问技术使用的基本步骤及方法
查看>>
VUE-Vue.js之$refs,父组件访问、修改子组件中 的数据
查看>>
Vue-子组件改变父级组件的信息
查看>>
Python自动化之pytest常用插件
查看>>
Python自动化之pytest框架使用详解
查看>>
【正则表达式】以个人的理解帮助大家认识正则表达式
查看>>
性能调优之iostat命令详解
查看>>
性能调优之iftop命令详解
查看>>
非关系型数据库(nosql)介绍
查看>>