luogu#P9936. [NFLSPC #6] 等差数列

[NFLSPC #6] 等差数列

Background

Problem Description

Alek Sui has solved aia_i problems of difficulty ii on a well-known OJ called Codeforces. He wants to solve some more problems so that aia_i forms an arithmetic progression with a non-positive common difference, because the resulting chart looks nice.

Although Alek Sui can solve 42 problems a day, he still wants to solve as few additional problems as possible to reach the goal. You need to find the minimum number of new problems he must solve.

You may assume that there are enough problems of every difficulty on the OJ.

Input Format

The first line contains an integer TT, the number of test cases.

For each test case:

  • The first line contains an integer nn, the number of difficulty levels.
  • The second line contains nn integers aia_i.

Output Format

For each test case, output one integer per line, the answer.

6
2
822 1064
2
1064 822
4
1 3 4 2
4
2 4 3 1
6
2 6 2 1 4 4
9
9 9 8 2 4 4 3 5 3

242
0
6
4
17
25

Hint

For all testdata, 1T1001\leq T\leq 100, 1n,n1051\leq n, \sum n\leq 10 ^ 5, 1ai1091\leq a_i\leq 10 ^ 9.

  • Subtask 1 (3030 points): n103\sum n \leq 10 ^ 3.
  • Subtask 2 (7070 points): no special constraints.

Source: NFLSPC #6 L by Alex_Wei

Translated by ChatGPT 5