對於每一個問題,都有一個難度分數di,它是一個正數。 Jagger但願學生從最簡單到最難解決問題,所以這些問題按照其難度分數的升序排列。
難度差距定義爲任意兩個連續問題之間的難度分數之差。 賈格爾要最小化最大難度差距。 所以,他決定添加一個新問題。 能夠將新問題設計爲具備任何正數的難度分數,而且Jagger能夠將其添加到問題列表中的任何位置。 新列表中的難度分數也應該增長。
Jagger想知道最小的最大難度差距是多少。python
Input
For this problem there are multiple test cases. The first line contains a single
integer T (1 ≤ T ≤ 100) indicates the number of test cases. You are suggested to
write a loop to deal with different test cases.
Each test case consists of two lines. For each test case:
The first line contains one integer n(2 ≤ n ≤ 200), which is the number of
problems.
The second line contains n sorted integers t1; t2; :::; tn (0 < t1 < t2 < t3 < ::: <
tn≤ 500), which is the difficulty score for each problem.
Output
For each case, output the maximum possible number of problems.
Sample Input 1
33
3 5 10
4
5 6 20 22
2
1 10
Sample Output 1
375app
思路:找到最大間距而後除以2(向上取整),可是沒有完事,除以2獲得的數不必定是當前最大間隔,原來的第二大間隔可能比那個平分後的要大了。ide
python代碼:oop
T= int(input()) for t_ in range(T): n= int(input()) t= list(map(int, input().split())) if len(t) == 1: print(0) continue a = [] for i in range(1,len(t)): diff= t[i]-t[i-1] a.append(diff) a.sort(reverse=True) maxd = a[0] max2= a[1] # if(maxd==1): # print(2) ans= int((maxd+1)/2) if ans> max2: print(ans) else: print(max2)