307467: CF1360B. Honest Coach

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Honest Coach

题意翻译

你面前有 n 名运动员 运动员的编号从左到右分别是1--n你知道每个运动员的力量 编号为i的运动员的力量为si 你需要把所有运动员分到两队里,每队至少有一人,每名运动员必须在其中一队里。 你需要在第一队里最强壮的运动员和第二队里最虚弱的运动员的差距尽可能的小。 正式的,你想把运动员分成A,B两队导致价值∣max(A)−min(B)∣尽可能的小。 其中max(A)是A队中力量最大的,min(B)是队伍中力量最小的。 例如,如果n=5,力量分别为s={3,1,2,4,6};则最理想的分配是: 第一队 A={1,2,4};第二队B={3,6}; 这样一来最大的价值的绝对值是|4-3|=1,这个例子说明了一种最佳的分成两个团队的方法。输出最小的价值|max(A)-min(B)|。 #### 输入格式 第一行输入一个t( 1≤t≤1000 ) --输入中的测试用例数。接下来是t测试用例。 每组数据包含两行,第一行是n(2≤n≤50); 第二行包含n个数据S1,S2....Sn( 1≤Si≤1000 ) --Si表示每名运动员的力量 ,请注意,s值可能不明显。 #### 输出格式 每组数据输出一行--把所有运动员分成两队后的∣max(A)−min(B)∣的最小值。 每个运动员都必须是这两个队中的一个。

题目描述

There are $ n $ athletes in front of you. Athletes are numbered from $ 1 $ to $ n $ from left to right. You know the strength of each athlete — the athlete number $ i $ has the strength $ s_i $ . You want to split all athletes into two teams. Each team must have at least one athlete, and each athlete must be exactly in one team. You want the strongest athlete from the first team to differ as little as possible from the weakest athlete from the second team. Formally, you want to split the athletes into two teams $ A $ and $ B $ so that the value $ |\max(A) - \min(B)| $ is as small as possible, where $ \max(A) $ is the maximum strength of an athlete from team $ A $ , and $ \min(B) $ is the minimum strength of an athlete from team $ B $ . For example, if $ n=5 $ and the strength of the athletes is $ s=[3, 1, 2, 6, 4] $ , then one of the possible split into teams is: - first team: $ A = [1, 2, 4] $ , - second team: $ B = [3, 6] $ . In this case, the value $ |\max(A) - \min(B)| $ will be equal to $ |4-3|=1 $ . This example illustrates one of the ways of optimal split into two teams. Print the minimum value $ |\max(A) - \min(B)| $ .

输入输出格式

输入格式


The first line contains an integer $ t $ ( $ 1 \le t \le 1000 $ ) — the number of test cases in the input. Then $ t $ test cases follow. Each test case consists of two lines. The first line contains positive integer $ n $ ( $ 2 \le n \le 50 $ ) — number of athletes. The second line contains $ n $ positive integers $ s_1, s_2, \ldots, s_n $ ( $ 1 \le s_i \le 1000 $ ), where $ s_i $ — is the strength of the $ i $ -th athlete. Please note that $ s $ values may not be distinct.

输出格式


For each test case print one integer — the minimum value of $ |\max(A) - \min(B)| $ with the optimal split of all athletes into two teams. Each of the athletes must be a member of exactly one of the two teams.

输入输出样例

输入样例 #1

5
5
3 1 2 6 4
6
2 1 3 2 4 3
4
7 9 3 1
2
1 1000
3
100 150 200

输出样例 #1

1
0
2
999
50

说明

The first test case was explained in the statement. In the second test case, one of the optimal splits is $ A=[2, 1] $ , $ B=[3, 2, 4, 3] $ , so the answer is $ |2-2|=0 $ .

Input

题意翻译

你面前有 n 名运动员 运动员的编号从左到右分别是1--n你知道每个运动员的力量 编号为i的运动员的力量为si 你需要把所有运动员分到两队里,每队至少有一人,每名运动员必须在其中一队里。 你需要在第一队里最强壮的运动员和第二队里最虚弱的运动员的差距尽可能的小。 正式的,你想把运动员分成A,B两队导致价值∣max(A)−min(B)∣尽可能的小。 其中max(A)是A队中力量最大的,min(B)是队伍中力量最小的。 例如,如果n=5,力量分别为s={3,1,2,4,6};则最理想的分配是: 第一队 A={1,2,4};第二队B={3,6}; 这样一来最大的价值的绝对值是|4-3|=1,这个例子说明了一种最佳的分成两个团队的方法。输出最小的价值|max(A)-min(B)|。 #### 输入格式 第一行输入一个t( 1≤t≤1000 ) --输入中的测试用例数。接下来是t测试用例。 每组数据包含两行,第一行是n(2≤n≤50); 第二行包含n个数据S1,S2....Sn( 1≤Si≤1000 ) --Si表示每名运动员的力量 ,请注意,s值可能不明显。 #### 输出格式 每组数据输出一行--把所有运动员分成两队后的∣max(A)−min(B)∣的最小值。 每个运动员都必须是这两个队中的一个。

加入题单

算法标签: