CF1593D1.All are Same

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This problem is a simplified version of D2, but it has significant differences, so read the whole statement.

Polycarp has an array of nn (nn is even) integers a1,a2,…,ana_1, a_2, \dots, a_n. Polycarp conceived of a positive integer kk. After that, Polycarp began performing the following operations on the array: take an index ii (1≤i≤n1 \le i \le n) and reduce the number aia_i by kk.

After Polycarp performed some (possibly zero) number of such operations, it turned out that all numbers in the array became the same. Find the maximum kk at which such a situation is possible, or print −1-1 if such a number can be arbitrarily large.

本题是 D2 的简化版本,但存在显著差异,因此请完整阅读题干。

Polycarp 有一个长度为 nn(nn 为偶数)的整数数组 a1,a2,…,ana_1, a_2, \dots, a_n。Polycarp 构思了一个正整数 kk。随后,Polycarp 开始对数组执行如下操作:选择一个下标 ii(1≤i≤n1 \le i \le n),并将 aia_i 减少 kk。

在 Polycarp 执行了若干次(可能为零次)此类操作后,数组中所有数均变为相同值。请找出满足该情况的最大 kk;若这样的 kk 可以任意大,则输出 −1-1。

输入格式

The first line contains one integer tt (1≤t≤101 \le t \le 10) — the number of test cases. Then tt test cases follow.

Each test case consists of two lines. The first line contains an even integer nn (4≤n≤404 \le n \le 40) (nn is even). The second line contains nn integers a1,a2,…ana_1, a_2, \dots a_n (−106≤ai≤106-10^6 \le a_i \le 10^6).

It is guaranteed that the sum of all nn specified in the given test cases does not exceed 100100.

第一行包含一个整数 tt(1≤t≤101 \le t \le 10)—— 表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例由两行组成。第一行包含一个偶数 nn(4≤n≤404 \le n \le 40)(即 nn 为偶数)。第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(−106≤ai≤106-10^6 \le a_i \le 10^6)。

保证所有测试用例中给定的 nn 值之和不超过 100100。

输出格式

For each test case output on a separate line an integer kk (k≥1k \ge 1) — the maximum possible number that Polycarp used in operations on the array, or −1-1, if such a number can be arbitrarily large.

对于每个测试用例,在单独一行输出一个整数 kk(k≥1k \ge 1)——即 Polycarp 在数组上执行操作时所使用的最大可能数值;若该数值可以任意大,则输出 −1-1。

输入输出样例

  • 输入#1

    3
    6
    1 5 3 1 1 5
    8
    -1 0 1 -1 0 1 -1 0
    4
    100 -1000 -1000 -1000

    输出#1

    2
    1
    1100

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

首页