c++Codeforces Round 834 (Div. 3)E - The Humanoid

E. The Humanoid

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output:standard output

There are n� astronauts working on some space station. An astronaut with the number i� (1≤i≤n1≤�≤�) has power ai��.

An evil humanoid has made his way to this space station. The power of this humanoid is equal to hℎ. Also, the humanoid took with him two green serums and one blue serum.

In one second , a humanoid can do any of three actions:

  1. to absorb an astronaut with power strictly less humanoid power;
  2. to use green serum, if there is still one left;
  3. to use blue serum, if there is still one left.

When an astronaut with power ai�� is absorbed, this astronaut disappears, and power of the humanoid increases by ⌊ai2⌋⌊��2⌋, that is, an integer part of ai2��2. For example, if a humanoid absorbs an astronaut with power 44, its power increases by 22, and if a humanoid absorbs an astronaut with power 77, its power increases by 33.

After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by 22 times.

After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by 33 times.

The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally.

Input

The first line of each test contains an integer t� (1≤t≤1041≤�≤104) — number of test cases.

The first line of each test case contains integers n� (1≤n≤2⋅1051≤�≤2⋅105) — number of astronauts and hℎ (1≤h≤1061≤ℎ≤106) — the initial power of the humanoid.

The second line of each test case contains n� integers ai�� (1≤ai≤1081≤��≤108) — powers of astronauts.

It is guaranteed that the sum of n� for all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb.

Example

input

8

4 1

2 1 8 9

3 3

6 2 60

4 5

5 1 100 5

3 2

38 6 3

1 1

12

4 6

12 12 36 100

4 1

2 1 1 15

3 5

15 1 13

output

4

3

3

3

0

4

4

3

Note

In the first case, you can proceed as follows:

  1. use green serum. h=1⋅2=2ℎ=1⋅2=2
  2. absorb the cosmonaut 22. h=2+⌊12⌋=2ℎ=2+⌊12⌋=2
  3. use green serum. h=2⋅2=4ℎ=2⋅2=4
  4. absorb the spaceman 11. h=4+⌊22⌋=5ℎ=4+⌊22⌋=5
  5. use blue serum. h=5⋅3=15ℎ=5⋅3=15
  6. absorb the spaceman 33. h=15+⌊82⌋=19ℎ=15+⌊82⌋=19
  7. absorb the cosmonaut 44. h=19+⌊92⌋=23

AC:(c++)

Let's make two obvious remarks:

If we can absorb two astronauts with power x≤y
, then we can always first absorb an astronaut with power x
, and then an astronaut with power y
;
If we can absorb some astronaut, it is effective for us to do it right now.
Let's sort the astronauts powers in increasing order.

Now let's lock the sequence of serums we use. There are only three of them: blue serum can be the first, second or third.

Let's absorb the astronauts in increasing order of their powers, and if we can't, then use the next serum in a locked sequence or stop.

This solution works for O(n)
.
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200200;

int n;
int arr[MAXN];

int solve(int i, long long h, int s2, int s3) {
	if (i == n) return 0;
	if (arr[i] < h)
		return solve(i + 1, h + (arr[i] / 2), s2, s3) + 1;
	int ans1 = (s2 ? solve(i, h * 2, s2 - 1, s3) : 0);
	int ans2 = (s3 ? solve(i, h * 3, s2, s3 - 1) : 0);
	return max(ans1, ans2);
}

int main() {
	int t; cin >> t;
	while(t--) {
		long long h; cin >> n >> h;
		for (int i = 0; i < n; ++i)
			cin >> arr[i];
		sort(arr, arr + n);
		cout << solve(0, h, 2, 1) << endl;
	}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

浪子小院

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

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

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

打赏作者

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

抵扣说明:

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

余额充值