Codeforces Round #753 (Div. 3) C. Minimum Extraction

题目链接:Problem - C - Codeforces

Yelisey has an array aa of nn integers.

If aa has length strictly greater than 11, then Yelisei can apply an operation called minimum extraction to it:

  1. First, Yelisei finds the minimal number mm in the array. If there are several identical minima, Yelisey can choose any of them.
  2. Then the selected minimal element is removed from the array. After that, mm is subtracted from each remaining element.

Thus, after each operation, the length of the array is reduced by 11.

For example, if a=[1,6,−4,−2,−4]a=[1,6,−4,−2,−4], then the minimum element in it is a3=−4a3=−4, which means that after this operation the array will be equal to a=[1−(−4),6−(−4),−2−(−4),−4−(−4)]=[5,10,2,0]a=[1−(−4),6−(−4),−2−(−4),−4−(−4)]=[5,10,2,0].

Since Yelisey likes big numbers, he wants the numbers in the array aa to be as big as possible.

Formally speaking, he wants to make the minimum of the numbers in array aa to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length 11.

Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array.

Input

The first line contains an integer tt (1≤t≤104) — the number of test cases.

The next 2t2t lines contain descriptions of the test cases.

In the description of each test case, the first line contains an integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the original length of the array aa. The second line of the description lists nn space-separated integers aiai (−109≤ai≤109−109≤ai≤109) — elements of the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.

Output

Print tt lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in aa, which can be obtained by several applications of the described operation to it.

Example

input

Copy

8
1
10
2
0 0
3
-1 2 0
4
2 10 1 7
2
2 3
5
3 2 -4 -2 0
2
-1 1
1
-2

output

Copy

10
0
2
5
2
2
2
-2

Note

In the first example test case, the original length of the array n=1n=1. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is a1=10.

In the second set of input data, the array will always consist only of zeros.

In the third set, the array will be changing as follows: [−1,2,0]→[3,1]→[2][−1,2,0]→[3,1]→[2]. The minimum elements are highlighted with blueblue. The maximal one is 2.

In the fourth set, the array will be modified as [2,10,1,7]→[1,9,6]→[8,5]→[3][2,10,1,7]→[1,9,6]→[8,5]→[3]. Similarly, the maximum of the minimum elements is 5.

题意:每次找一个最小值然后删掉最小值,其他每个值减最小值,然后找最小值,问这样的最大值是多少(操作可以是0次)

思路:我们每次可以减掉后的最小是从小到大排序后的后一个与这个的最小值的差值,我们可以 排序后将最小值定义成初始值,然后遍历一遍去找相邻的差值中的最大值

#include<bits/stdc++.h>
using namespace std;
 
int arr[200005];
 
int main(){
	int t;
	cin >> t;
	int n;
	while(t--){
		cin >> n;
		for(int i = 0; i < n; i++){
			cin >> arr[i];
		} 
		sort(arr, arr + n);
		
		int maxn = arr[0];
		for(int i = 1; i < n; i++){
			maxn = max(maxn, arr[i] - arr[i - 1]);
		}
		
		cout << maxn << endl;
	}
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值