CF1840D.Wooden Toy Festival

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In a small town, there is a workshop specializing in woodwork. Since the town is small, only three carvers work there.

Soon, a wooden toy festival is planned in the town. The workshop employees want to prepare for it.

They know that nn people will come to the workshop with a request to make a wooden toy. People are different and may want different toys. For simplicity, let's denote the pattern of the toy that the ii-th person wants as aia_i (1≤ai≤1091 \le a_i \le 10^9).

Each of the carvers can choose an integer pattern xx (1≤x≤1091 \le x \le 10^9) in advance, different carvers can choose different patterns. xx is the integer. During the preparation for the festival, the carvers will perfectly work out the technique of making the toy of the chosen pattern, which will allow them to cut it out of wood instantly. To make a toy of pattern yy for a carver who has chosen pattern xx, it will take ∣x−y∣|x - y| time, because the more the toy resembles the one he can make instantly, the faster the carver will cope with the work.

On the day of the festival, when the next person comes to the workshop with a request to make a wooden toy, the carvers can choose who will take on the job. At the same time, the carvers are very skilled people and can work on orders for different people simultaneously.

Since people don't like to wait, the carvers want to choose patterns for preparation in such a way that the maximum waiting time over all people is as small as possible.

Output the best maximum waiting time that the carvers can achieve.

在一个小镇上,有一家专精于木工的作坊。由于小镇规模较小,作坊里仅有三名木雕师。

不久后,小镇计划举办一场木制玩具节,作坊员工希望为此做好准备。

他们已知将有 nn 位顾客来到作坊,每人提出制作一款木制玩具的需求。每位顾客的需求各不相同,可能想要不同样式的玩具。为简化问题,我们将第 ii 位顾客想要的玩具样式记为 aia_i(其中 1≤ai≤1091 \le a_i \le 10^9)。

每名木雕师可在筹备阶段预先选定一个整数样式 xx(1≤x≤1091 \le x \le 10^9),不同木雕师可选择不同的样式。该整数 xx 即为其专精样式。在节日前的筹备过程中,每位木雕师将完美掌握其选定样式的制作技巧,从而能瞬间将其从木材中雕刻出来。对于一名已选定样式 xx 的木雕师,若需制作样式为 yy 的玩具,则所需时间为 ∣x−y∣|x - y|,因为待制玩具与该木雕师专精样式越接近,其完成速度就越快。

节日期间,当一位顾客前来提出制作需求时,木雕师们可自由决定由谁来承接该订单;同时,这些技艺高超的木雕师能够并行处理多位顾客的订单。

由于顾客不愿久等,木雕师们希望预先选定三个样式,使得所有顾客中最大等待时间尽可能小。

请输出木雕师们所能达到的最优(即最小可能的)最大等待时间。

输入格式

The first line of the input contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Then follow the descriptions of the test cases.

The first line of a test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of people who will come to the workshop.

The second line of a test case contains nn integers a1,a2,a3,…,ana_1, a_2, a_3, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the patterns of toys.

The sum of all nn values over all test cases does not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示将参加工作坊的人数。

每个测试用例的第二行包含 nn 个整数 a1,a2,a3,…,ana_1, a_2, a_3, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 表示玩具的图案。

所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

Output tt numbers, each of which is the answer to the corresponding test case — the best maximum waiting time that the carvers can achieve.

输出 tt 个数字,每个数字对应一个测试用例的答案——雕刻师们所能达到的最佳最大等待时间。

输入输出样例

  • 输入#1

    5
    6
    1 7 7 9 9 9
    6
    5 4 2 1 30 60
    9
    14 19 37 59 1 4 4 98 73
    1
    2
    6
    3 10 1 17 15 11

    输出#1

    0
    2
    13
    0
    1

说明/提示

In the first example, the carvers can choose patterns 11, 77, 99 for preparation.

In the second example, the carvers can choose patterns 33, 3030, 6060 for preparation.

In the third example, the carvers can choose patterns 1414, 5050, 8585 for preparation.

在第一个例子中,雕刻师可以选择图案 11、77、99 进行准备。

在第二个例子中,雕刻师可以选择图案 33、3030、6060 进行准备。

在第三个例子中,雕刻师可以选择图案 1414、5050、8585 进行准备。

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

首页