CF1360B.Honest Coach

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn athletes in front of you. Athletes are numbered from 11 to nn from left to right. You know the strength of each athlete — the athlete number ii has the strength sis_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 AA and BB so that the value ∣max⁡(A)−min⁡(B)∣|\max(A) - \min(B)| is as small as possible, where max⁡(A)\max(A) is the maximum strength of an athlete from team AA, and min⁡(B)\min(B) is the minimum strength of an athlete from team BB.

For example, if n=5n=5 and the strength of the athletes is s=[3,1,2,6,4]s=[3, 1, 2, 6, 4], then one of the possible split into teams is:

  • first team: A=[1,2,4]A = [1, 2, 4],
  • second team: B=[3,6]B = [3, 6].

In this case, the value ∣max⁡(A)−min⁡(B)∣|\max(A) - \min(B)| will be equal to ∣4−3∣=1|4-3|=1. This example illustrates one of the ways of optimal split into two teams.

Print the minimum value ∣max⁡(A)−min⁡(B)∣|\max(A) - \min(B)|.

你面前有 nn 名运动员。运动员从左到右编号为 11 到 nn。你知道每名运动员的力量值——编号为 ii 的运动员力量为 sis_i。

你想将所有运动员分成两支队伍。每支队伍至少包含一名运动员,且每名运动员必须恰好属于其中一支队伍。

你希望第一支队伍中最强运动员的力量值与第二支队伍中最弱运动员的力量值之间的差尽可能小。形式化地说,你需要将运动员划分为两支队伍 AA 和 BB,使得值 ∣max⁡(A)−min⁡(B)∣|\max(A) - \min(B)| 尽可能小,其中 max⁡(A)\max(A) 表示队伍 AA 中运动员的最大力量值,min⁡(B)\min(B) 表示队伍 BB 中运动员的最小力量值。

例如,若 n=5n=5,且运动员力量为 s=[3,1,2,6,4]s=[3, 1, 2, 6, 4],则一种可能的分队方式是:

  • 第一支队伍:A=[1,2,4]A = [1, 2, 4],
  • 第二支队伍:B=[3,6]B = [3, 6]。

此时,值 ∣max⁡(A)−min⁡(B)∣|\max(A) - \min(B)| 等于 ∣4−3∣=1|4-3|=1。该例子展示了一种最优分队方式。

请输出最小的 ∣max⁡(A)−min⁡(B)∣|\max(A) - \min(B)| 值。

输入格式

The first line contains an integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases in the input. Then tt test cases follow.

Each test case consists of two lines.

The first line contains positive integer nn (2≤n≤502 \le n \le 50) — number of athletes.

The second line contains nn positive integers s1,s2,…,sns_1, s_2, \ldots, s_n (1≤si≤10001 \le s_i \le 1000), where sis_i — is the strength of the ii-th athlete. Please note that ss values may not be distinct.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 输入中测试用例的数量。随后是 tt 个测试用例。

每个测试用例由两行组成。

第一行包含一个正整数 nn(2≤n≤502 \le n \le 50)—— 运动员的数量。

第二行包含 nn 个正整数 s1,s2,…,sns_1, s_2, \ldots, s_n(1≤si≤10001 \le s_i \le 1000),其中 sis_i 表示第 ii 位运动员的力量值。请注意,ss 的值可能不互异。

输出格式

For each test case print one integer — the minimum value of ∣max⁡(A)−min⁡(B)∣|\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.

对于每个测试用例,输出一个整数——即在将所有运动员最优地分为两支队伍时,∣max⁡(A)−min⁡(B)∣|\max(A) - \min(B)| 的最小值。每名运动员必须且仅能属于这两支队伍中的一支。

输入输出样例

  • 输入#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]A=[2, 1], B=[3,2,4,3]B=[3, 2, 4, 3], so the answer is ∣2−2∣=0|2-2|=0.

第一个测试用例已在题目描述中解释。在第二个测试用例中,一种最优的划分方式是 A=[2,1]A=[2, 1],B=[3,2,4,3]B=[3, 2, 4, 3],因此答案为 ∣2−2∣=0|2-2|=0。

输入解题思路,AI测评打分。不知道怎么写?

首页