CF1904C.Array Game

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa of nn positive integers. In one operation, you must pick some (i,j)(i, j) such that 1≤i<j≤∣a∣1\leq i \lt j\leq |a| and append ∣ai−aj∣|a_i - a_j| to the end of the aa (i.e. increase nn by 11 and set ana_n to ∣ai−aj∣|a_i - a_j|). Your task is to minimize and print the minimum value of aa after performing kk operations.

给你一个包含 nn 个正整数的数组 aa。在一次操作中,你必须选择一对下标 (i,j)(i, j),满足 1≤i<j≤∣a∣1\leq i \lt j\leq |a|,并将 ∣ai−aj∣|a_i - a_j| 追加到数组 aa 的末尾(即令 nn 增加 11,并设 an=∣ai−aj∣a_n = |a_i - a_j|)。你的任务是在执行 kk 次操作后,最小化数组 aa 中的最小值,并输出该最小值。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and kk (2≤n≤2⋅1032\le n\le 2\cdot 10^3, 1≤k≤1091\le k\le 10^9) — the length of the array and the number of operations you should perform.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤10181\le a_i\le 10^{18}) — the elements of the array aa.

It is guaranteed that the sum of n2n^2 over all test cases does not exceed 4⋅1064\cdot 10^6.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(2≤n≤2⋅1032\le n\le 2\cdot 10^3,1≤k≤1091\le k\le 10^9),分别表示数组的长度以及你需要执行的操作次数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤10181\le a_i\le 10^{18}),表示数组 aa 的元素。

保证所有测试用例中 n2n^2 的总和不超过 4⋅1064\cdot 10^6。

输出格式

For each test case, print a single integer — the smallest possible value of the minimum of array aa after performing kk operations.

对于每个测试用例,输出一个整数——在执行 kk 次操作后,数组 aa 的最小值的最小可能值。

输入输出样例

  • 输入#1

    4
    5 2
    3 9 7 15 1
    4 3
    7 4 15 12
    6 2
    42 47 50 54 62 79
    2 1
    500000000000000000 1000000000000000000

    输出#1

    1
    0
    3
    500000000000000000

说明/提示

In the first test case, after any k=2k=2 operations, the minimum value of aa will be 11.

In the second test case, an optimal strategy is to first pick i=1,j=2i=1, j=2 and append ∣a1−a2∣=3|a_1 - a_2| = 3 to the end of aa, creating a=[7,4,15,12,3]a=[7, 4, 15, 12, 3]. Then, pick i=3,j=4i=3, j=4 and append ∣a3−a4∣=3|a_3 - a_4| = 3 to the end of aa, creating a=[7,4,15,12,3,3]a=[7, 4, 15, 12, 3, 3]. In the final operation, pick i=5,j=6i=5, j=6 and append ∣a5−a6∣=0|a_5 - a_6| = 0 to the end of aa. Then the minimum value of aa will be 00.

In the third test case, an optimal strategy is to first pick i=2,j=3i=2, j=3 to append ∣a2−a3∣=3|a_2 - a_3| = 3 to the end of aa. Any second operation will still not make the minimum value of aa be less than 33.

在第一个测试用例中,经过任意 k=2k=2 次操作后,数组 aa 的最小值为 11。

在第二个测试用例中,一种最优策略是:首先选择 i=1,j=2i=1, j=2,将 ∣a1−a2∣=3|a_1 - a_2| = 3 追加到 aa 末尾,得到 a=[7,4,15,12,3]a=[7, 4, 15, 12, 3];接着选择 i=3,j=4i=3, j=4,将 ∣a3−a4∣=3|a_3 - a_4| = 3 追加到 aa 末尾,得到 a=[7,4,15,12,3,3]a=[7, 4, 15, 12, 3, 3];最后一步操作中,选择 i=5,j=6i=5, j=6,将 ∣a5−a6∣=0|a_5 - a_6| = 0 追加到 aa 末尾。此时,数组 aa 的最小值为 00。

在第三个测试用例中,一种最优策略是首先选择 i=2,j=3i=2, j=3,将 ∣a2−a3∣=3|a_2 - a_3| = 3 追加到 aa 末尾。无论进行何种第二次操作,数组 aa 的最小值均不会小于 33。

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

首页