A. Gamer Hemose

题目如下:

One day, Ahmed_Hossam went to Hemose and said "Let's solve a gym contest!". Hemose didn't want to do that, as he was playing Valorant, so he came up with a problem and told it to Ahmed to distract him. Sadly, Ahmed can't solve it... Could you help him?

There is an Agent in Valorant, and he has n

weapons. The i-th weapon has a damage value ai, and the Agent will face an enemy whose health value is H

.

The Agent will perform one or more moves until the enemy dies.

In one move, he will choose a weapon and decrease the enemy's health by its damage value. The enemy will die when his health will become less than or equal to 0

. However, not everything is so easy: the Agent can't choose the same weapon for 2

times in a row.

What is the minimum number of times that the Agent will need to use the weapons to kill the enemy?

Input

Each test contains multiple test cases. The first line contains the number of test cases t

(1≤t≤105)

. Description of the test cases follows.

The first line of each test case contains two integers n

and H (2≤n≤103,1≤H≤109)

— the number of available weapons and the initial health value of the enemy.

The second line of each test case contains n

integers a1,a2,…,an (1≤ai≤109)

— the damage values of the weapons.

It's guaranteed that the sum of n

over all test cases doesn't exceed 2⋅105

.

Output

For each test case, print a single integer — the minimum number of times that the Agent will have to use the weapons to kill the enemy.

Example

Input

3
2 4
3 7
2 6
4 2
3 11
2 1 7

Output

1
2
3

Note

In the first test case, the Agent can use the second weapon, making health value of the enemy equal to 4−7=−3

. −3≤0, so the enemy is dead, and using weapon 1

time was enough.

In the second test case, the Agent can use the first weapon first, and then the second one. After this, the health of enemy will drop to 6−4−2=0

, meaning he would be killed after using weapons 2

times.

In the third test case, the Agent can use the weapons in order (third, first, third), decreasing the health value of enemy to 11−7−2−7=−5

after using the weapons 3 times. Note that we can't kill the enemy by using the third weapon twice, as even though 11−7−7<0

, it's not allowed to use the same weapon twice in a row.

AC代码如下:

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int s[1010];
int main()
{
	int t,i;
	scanf("%d", &t);
	long long num, hp;
	long long max1 = 0, max2 = 0;
	while (t--)
	{
		memset(s, 0, sizeof s);
		scanf("%lld %lld", &num, &hp);
		int tmp;
		for (i = 1; i <= num; i++)
		{
			scanf("%d", &tmp);
			s[i] = tmp;
		}
		sort(s+1 , s + 1 + num);
		max1 = s[num];
		max2 = s[num - 1];
		//攻击模块
		long long x = max1 + max2;
		long long y = hp / x;
		hp -= y * x;
		long long count = y * 2;
		if (hp > 0)
		{
			if (hp - max1 > 0)
				count += 2;
			else
			{
				count++;
			}
		}
		printf("%lld\n", count);
	}
	return 0;
}

代码解析:

问题的核心:找到最大与第二大的攻击力

在这里直接使用C++中的sort,可以简洁并快速的找到最大与第二大的值。

注意!!!——————》如果你也像我一样单纯的循环(-A  -B;再判断的话)是一定T的,可以再看一眼题目的数据,你应该就可以理解T的原因了!

所以在这里要用    ——————》除(具体看上文的代码)

ps:这个题虽然思维难度上不大,但想A也不容易,一些细节要处理得当才可以!

开学的第二天,我感觉ACM的路越来越近,我一定会加油努力的!!!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Joanh_Lan

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

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

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

打赏作者

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

抵扣说明:

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

余额充值