CF1607C.Minimum Extraction
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yelisey has an array a of n integers.
If a has length strictly greater than 1, then Yelisei can apply an operation called minimum extraction to it:
- First, Yelisei finds the minimal number m in the array. If there are several identical minima, Yelisey can choose any of them.
- 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 1.
For example, if a=[1,6,−4,−2,−4], then the minimum element in it is a3=−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].
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 1.
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.
叶列谢有一个包含 n 个整数的数组 a。
若 a 的长度严格大于 1,则叶列谢可以对其执行一种称为“最小值提取”的操作:
- 首先,叶列谢找出数组中的最小数 m。若存在多个相同的最小值,叶列谢可任选其一。
- 然后,将所选的最小元素从数组中移除;接着,将 m 从每个剩余元素中减去。
因此,每次操作后,数组长度减少 1。
例如,若 a=[1,6,−4,−2,−4],则其中最小元素为 a3=−4,于是该操作后数组变为 a=[1−(−4),6−(−4),−2−(−4),−4−(−4)]=[5,10,2,0]。
由于叶列谢喜欢较大的数,他希望数组 a 中的数尽可能大。
形式化地说,他希望使数组 a 中各数的最小值尽可能大(即最大化该最小值)。为此,叶列谢可以对数组执行任意多次(包括零次)最小值提取操作。注意:该操作不能在长度为 1 的数组上执行。
请帮助他求出:对数组执行若干次(可能为零次)最小值提取操作后,数组中最小元素所能达到的最大值。
输入格式
The first line contains an integer t (1≤t≤104) — the number of test cases.
The next 2t lines contain descriptions of the test cases.
In the description of each test case, the first line contains an integer n (1≤n≤2⋅105) — the original length of the array a. The second line of the description lists n space-separated integers ai (−109≤ai≤109) — elements of the array a.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
接下来的 2t 行包含各测试用例的描述。
在每个测试用例的描述中,第一行包含一个整数 n(1≤n≤2⋅105)—— 数组 a 的原始长度。描述的第二行包含 n 个以空格分隔的整数 ai(−109≤ai≤109)—— 数组 a 的元素。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
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.
输出 t 行,每行包含对应测试用例的答案。每个测试用例的答案是一个整数——即通过对数组 a 多次应用上述操作所能得到的最大可能的最小值。
输入输出样例
输入#1
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
输出#1
10 0 2 5 2 2 2 -2
说明/提示
In the first example test case, the original length of the array n=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]. The minimum elements are highlighted with blue. 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]. Similarly, the maximum of the minimum elements is 5.
在第一个样例测试用例中,数组的原始长度为 n=1。因此无法应用最小值提取操作。于是数组保持不变,答案为 a1=10。
在第二组输入数据中,数组将始终仅由零组成。
在第三组中,数组的变化过程如下:[−1,2,0]→[3,1]→[2]。被标为 蓝色 的元素为每次操作中被提取的最小元素。这些最小元素中的最大值为 2。
在第四组中,数组的变化过程为 [2,10,1,7]→[1,9,6]→[8,5]→[3]。类似地,所有被提取的最小元素中的最大值为 5。
输入解题思路,AI测评打分。不知道怎么写?