Codeforces-Middle Class

山再高,往上爬,总能登顶;
路再长,走下去,定能到达。

Codeforces-Middle Class

题目描述

Many years ago Berland was a small country where only nn people lived. Each person had some savings: the i-th one had aiai 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 11-st and the 3-rd persons then it, at first, will take all 5+2=7burles 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.

输入

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 nn integers a1,a2,…,an (1≤ai≤109) — the initial savings of each person.
It’s guaranteed that the total sum of nn doesn’t exceed 105.

输出

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

Sample Input

4
4 3
5 1 2 1
4 10
11 9 11 9
2 5
4 3
3 7
9 4 9

Sample Output

2
4
0
3

Hint

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]→[7+1/3,7+1/3,7+1/3].

题目大意

首先两个数,分别为有多少个居民,至少多少钱才算是富豪,接下来给出每个人的钱数多少,可以任意选几个人进行平分钱财。问最后最多可以有几个符号

题目解析
如果说一个人拖后腿了,那么只要你带着他,他一定是拖后腿的,所以说。金额低的人就不管他了。只要能在其余的人当中能找到更优解就可以了。所以这题用到了一丢丢的贪心思路。怎么贪心呢,就是排个序,从小到大,如果说全算的平均达不到要求,那么就把金额最低的人剔除掉其余的人重复昨天的故事。接下来请看代码。🦆🦆🦆.

AC时间到

#include<algorithm>
#include<iostream>
#include<string.h>
#include<utility>
#include<stdio.h>
#include<vector>
#include<string>
#include<math.h>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#pragma warning(disable:4244)
#define PI 3.1415926536
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll ll_inf = 9223372036854775807;
const int int_inf = 2147483647;
const short short_inf = 32767;
const char char_inf = 127;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
inline ll read() {
	ll c = getchar(), Nig = 1, x = 0;
	while (!isdigit(c) && c != '-')c = getchar();
	if (c == '-')Nig = -1, c = getchar();
	while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
	return Nig * x;
}
inline void out(ll a) {
	if (a < 0)putchar('-'), a = -a;
	if (a >= 10)out(a / 10);
	putchar(a % 10 + '0');
}
ll qpow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1)res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}
#define Floyd for(int k = 1; k <= n; k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
#define read read()
ll save[1000000];
int main() {
	ll T = read;
	while (T--) {
		ll tot = 0;
		ll n = read, x = read;
		for (ll i = 1; i <= n; i++)save[i] = read;
		sort(save + 1, save + 1 + n);
		for (ll i = 1; i <= n; i++)tot += save[i];
		for (ll i = 0; i <= n; i++) {
			tot -= save[i];
			double temp = 1.0 * tot / (1.0 * (n - i));
			if (temp >= (double)x) {
				out(n - i);
				puts("");
				goto END;
			}
		}
		puts("0");
	END:
		;
	}
}

思路很简单,就是一个个去除掉。应该没啥疑问吧,有疑问或错误的话请在评论区留言叭🐒🐒🐒

By-轮月

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Round Moon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值