CF1899B.250 Thousand Tons of TNT

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alex is participating in the filming of another video of BrMeast, and BrMeast asked Alex to prepare 250 thousand tons of TNT, but Alex didn't hear him well, so he prepared nn boxes and arranged them in a row waiting for trucks. The ii-th box from the left weighs aia_i tons.

All trucks that Alex is going to use hold the same number of boxes, denoted by kk. Loading happens the following way:

  • The first kk boxes goes to the first truck,
  • The second kk boxes goes to the second truck,
  • ⋯\dotsb
  • The last kk boxes goes to the nk\frac{n}{k}-th truck.

Upon loading is completed, each truck must have exactly kk boxes. In other words, if at some point it is not possible to load exactly kk boxes into the truck, then the loading option with that kk is not possible.

Alex hates justice, so he wants the maximum absolute difference between the total weights of two trucks to be as great as possible. If there is only one truck, this value is 00.

Alex has quite a lot of connections, so for every 1≤k≤n1 \leq k \leq n, he can find a company such that each of its trucks can hold exactly kk boxes. Print the maximum absolute difference between the total weights of any two trucks.

Alex 正在参与 BrMeast 另一支视频的拍摄,BrMeast 要求 Alex 准备 25 万吨 TNT,但 Alex 没听清楚,于是他准备了 nn 个箱子,并将它们排成一列等待卡车装运。从左往右数第 ii 个箱子的重量为 aia_i 吨。

Alex 将使用的全部卡车每辆装载的箱子数量相同,记为 kk。装运过程如下:

  • 前 kk 个箱子装入第一辆卡车,
  • 接下来的 kk 个箱子装入第二辆卡车,
  • ⋯\dotsb
  • 最后 kk 个箱子装入第 nk\frac{n}{k} 辆卡车。

装运完成后,每辆卡车必须恰好装有 kk 个箱子。换言之,若在某一步无法恰好装入 kk 个箱子,则该 kk 值对应的装运方案不可行。

Alex 讨厌公平,因此他希望任意两辆卡车总重量之差的绝对值尽可能大。若仅有一辆卡车,则该值为 00。

Alex 人脉很广,因此对每个满足 1≤k≤n1 \leq k \leq n 的 kk,他都能找到一家公司,其每辆卡车恰好可装载 kk 个箱子。请输出所有可行 kk 值中,任意两辆卡车总重量之差的绝对值的最大值。

输入格式

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

The first line of each test case contains one integer nn (1≤n≤150 0001 \leq n \leq 150\,000) — the number of boxes.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \leq a_i \leq 10^9) — the weights of the boxes.

It is guaranteed that the sum of nn for all test cases does not exceed 150 000150\,000.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤150 0001 \leq n \leq 150\,000)—— 箱子的数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— 各箱子的重量。

保证所有测试用例的 nn 之和不超过 150 000150\,000。

输出格式

For each test case, print a single integer — the answer to the problem.

对于每个测试用例,输出一个整数——即该问题的答案。

输入输出样例

  • 输入#1

    5
    2
    1 2
    6
    10 2 3 6 1 3
    4
    1000000000 1000000000 1000000000 1000000000
    15
    60978 82265 78961 56708 39846 31071 4913 4769 29092 91348 64119 72421 98405 222 14294
    8
    19957 69913 37531 96991 57838 21008 14207 19198

    输出#1

    1
    9
    0
    189114
    112141

说明/提示

In the first case, we should pick two trucks, so the first one will have only the first box, and the second one will have only the second box.

In the second case, we should pick six trucks, so the maximum will be 1010, the minimum will be 11, and the answer is 10−1=910 - 1 = 9.

In the third case, for any possible kk, the trucks will have the same total weight of boxes, so the answer is 00.

第一种情况,我们需要选择两辆卡车,因此第一辆卡车只装载第一个箱子,第二辆卡车只装载第二个箱子。

第二种情况,我们需要选择六辆卡车,此时最大总重量为 1010,最小总重量为 11,答案为 10−1=910 - 1 = 9。

第三种情况,对于任意可能的 kk,每辆卡车所装载的箱子总重量均相同,因此答案为 00。

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

首页