CF1853A.Desorting

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Call an array aa of length nn sorted if a1a2an1ana_1 \leq a_2 \leq \ldots \leq a_{n-1} \leq a_n .

Ntarsis has an array aa of length nn .

He is allowed to perform one type of operation on it (zero or more times):

  • Choose an index ii ( 1in11 \leq i \leq n-1 ).
  • Add 11 to a1,a2,,aia_1, a_2, \ldots, a_i .
  • Subtract 11 from ai+1,ai+2,,ana_{i+1}, a_{i+2}, \ldots, a_n .

The values of aa can be negative after an operation.

Determine the minimum operations needed to make aa not sorted.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1001 \le t \le 100 ). The description of the test cases follows.

The first line of each test case contains a single integer nn ( 2n5002 \leq n \leq 500 ) — the length of the array aa .

The next line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai1091 \leq a_i \leq 10^9 ) — the values of array aa .

It is guaranteed that the sum of nn across all test cases does not exceed 500500 .

输出格式

Output the minimum number of operations needed to make the array not sorted.

输入输出样例

  • 输入#1

    4
    2
    1 1
    4
    1 8 10 13
    3
    1 3 2
    3
    1 9 14

    输出#1

    1
    2
    0
    3

说明/提示

In the first case, we can perform 11 operation to make the array not sorted:

  • Pick i=1i = 1 . The array aa then becomes [2,0][2, 0] , which is not sorted.

In the second case, we can perform 22 operations to make the array not sorted:

  • Pick i=3i = 3 . The array aa then becomes [2,9,11,12][2, 9, 11, 12] .
  • Pick i=3i = 3 . The array aa then becomes [3,10,12,11][3, 10, 12, 11] , which is not sorted.

It can be proven that 11 and 22 operations are the minimal numbers of operations in the first and second test cases, respectively.

In the third case, the array is already not sorted, so we perform 00 operations.

首页