Algorithm


C. Minimum Extraction
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Yelisey has an array a of n integers.

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

  1. First, Yelisei finds the minimal number m 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, m 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]�=[1,6,−4,−2,−4], then the minimum element in it is a3=4�3=−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]�=[1−(−4),6−(−4),−2−(−4),−4−(−4)]=[5,10,2,0].

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

Formally speaking, he wants to make the minimum of the numbers in array a 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 t (1t1041≤�≤104) — the number of test cases.

The next 2t2� lines contain descriptions of the test cases.

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

It is guaranteed that the sum of n over all test cases does not exceed 21052⋅105.

Output

Print t 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 a, 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=1�=1. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is a1=10�1=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 22.

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 55.

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll t;
  cin>>t;
  while(t--){
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0; i < n; i++){
      cin>>arr[i];
    }
    sort(arr, arr + n);
    int brr[n];
    brr[0] = arr[0];
    for(int i = 1; i < n; i++){
      brr[i] = arr[i] - arr[i - 1];
    }
    sort(brr, brr+n, greater<int>());
    cout<<brr[0]<<endl;
  }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
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

x
+
cmd
10
0
2
5
2
2
2
-2
Advertisements

Demonstration


Codeforcess Solution 1607-C C. Minimum Extraction ,C++, Java, Js and Python ,1607-C,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+