Poisoned Dagger CodeForces - 1613C

Poisoned Dagger - CodeForces 1613C - Virtual Judgeicon-default.png?t=M0H8https://vjudge.net/problem/CodeForces-1613C

Monocarp is playing yet another computer game. In this game, his character has to kill a dragon. The battle with the dragon lasts 100^{500}100500 seconds, during which Monocarp attacks the dragon with a poisoned dagger. The ii-th attack is performed at the beginning of the a_iai​-th second from the battle start. The dagger itself does not deal damage, but it applies a poison effect on the dragon, which deals 11 damage during each of the next kk seconds (starting with the same second when the dragon was stabbed by the dagger). However, if the dragon has already been poisoned, then the dagger updates the poison effect (i.e. cancels the current poison effect and applies a new one).

For example, suppose k = 4k=4, and Monocarp stabs the dragon during the seconds 22, 44 and 1010. Then the poison effect is applied at the start of the 22-nd second and deals 11 damage during the 22-nd and 33-rd seconds; then, at the beginning of the 44-th second, the poison effect is reapplied, so it deals exactly 11 damage during the seconds 44, 55, 66 and 77; then, during the 1010-th second, the poison effect is applied again, and it deals 11 damage during the seconds 1010, 1111, 1212 and 1313. In total, the dragon receives 1010 damage.

Monocarp knows that the dragon has hh hit points, and if he deals at least hh damage to the dragon during the battle — he slays the dragon. Monocarp has not decided on the strength of the poison he will use during the battle, so he wants to find the minimum possible value of kk (the number of seconds the poison effect lasts) that is enough to deal at least hh damage to the dragon.

Input

The first line contains a single integer tt (1 \le t \le 10001≤t≤1000) — the number of test cases.

The first line of the test case contains two integers nn and hh (1 \le n \le 100; 1 \le h \le 10^{18}1≤n≤100;1≤h≤1018) — the number of Monocarp's attacks and the amount of damage that needs to be dealt.

The second line contains nn integers a_1a1​, a_2a2​, ..., a_nan​ (1 \le a_i \le 10^9; a_i < a_{i + 1}1≤ai​≤109;ai​<ai+1​), where a_iai​ is the second when the ii-th attack is performed.

Output

For each test case, print a single integer — the minimum value of the parameter kk, such that Monocarp will cause at least hh damage to the dragon.

Example

Input

4
2 5
1 5
3 10
2 4 10
5 3
1 2 4 5 7
4 1000
3 25 64 1337

Output

3
4
1
470

Note

In the first example, for k=3k=3, damage is dealt in seconds [1, 2, 3, 5, 6, 7][1,2,3,5,6,7].

In the second example, for k=4k=4, damage is dealt in seconds [2, 3, 4, 5, 6, 7, 10, 11, 12, 13][2,3,4,5,6,7,10,11,12,13].

In the third example, for k=1k=1, damage is dealt in seconds [1, 2, 4, 5, 7][1,2,4,5,7].

#include<iostream>
using namespace std;
#include<string>
#include<algorithm>
#pragma warning (disable:4996)
#include <climits>
#include <vector>
#include<stack>
long long arr[1000];
long long min(long long a, long long b);
int main() {
	int t;
	cin >> t;
	for (int cnt = 0; cnt < t; cnt++) {
		long long  n, h;
		cin >> n >> h;
		for (int cnt1 = 0; cnt1 < n; cnt1++) {
			cin >> arr[cnt1];
		}
		long long low = 1, high = h, mid;
		while (low <= high) {
			long long sum = 0;
			mid = (low + high) / 2;
			for (int cnt1 = 0; cnt1 < n; cnt1++) {
				if (cnt1 == n - 1) {
					sum += mid;
					continue;
				}
				sum += min(arr[cnt1 + 1] - arr[cnt1], mid);
			}
			if (sum > h)high = mid - 1;
			else if (sum < h) low = mid + 1;
			else {
				cout << mid;
				break;
			}
		}
		if (low > high)cout << low;
		cout << endl;
	}
}
long long min(long long a, long long b) {
	return a < b ? a : b;
}

这道题比较奇特,我想了半天应该怎么确保输出的是至少的那个值,后面证出来所有sum>h的全部-1以后,会有个很奇妙的性质,只要是<=的条件的话,那么low那里指的一定就是至少的那个位置然后我又想了一种情况,就是全部如果low 和high都在比h大的那边的话会怎么样,然后验证了因为左边只能加一然后和high相同,所以此时就是我们求得情况,然后我验证了下差两位的情况,发现假如在目标h值前有两个值,比如36.5是h值,后面是37,38,那么假设low和high是在38的位置,情况不成立,因为low退一位得到的是37,此时计算中间值应该是37.5不是36.5,并且中间值大于h,所以移动的应该是high而不是low

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

cjz-lxg

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

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

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

打赏作者

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

抵扣说明:

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

余额充值