CF1901B.Chip and Ribbon

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There is a ribbon divided into nn cells, numbered from 11 to nn from left to right. Initially, an integer 00 is written in each cell.

Monocarp plays a game with a chip. The game consists of several turns. During the first turn, Monocarp places the chip in the 11 -st cell of the ribbon. During each turn except for the first turn, Monocarp does exactly one of the two following actions:

  • move the chip to the next cell (i. e. if the chip is in the cell ii , it is moved to the cell i+1i+1 ). This action is impossible if the chip is in the last cell;
  • choose any cell xx and teleport the chip into that cell. It is possible to choose the cell where the chip is currently located.

At the end of each turn, the integer written in the cell with the chip is increased by 11 .

Monocarp's goal is to make some turns so that the 11 -st cell contains the integer c1c_1 , the 22 -nd cell contains the integer c2c_2 , ..., the nn -th cell contains the integer cnc_n . He wants to teleport the chip as few times as possible.

Help Monocarp calculate the minimum number of times he has to teleport the chip.

输入格式

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

Each test case consists of two lines:

  • the first line contains one integer nn ( 1n21051 \le n \le 2 \cdot 10^5 );
  • the second line contains nn integers c1,c2,,cnc_1, c_2, \dots, c_n ( 0ci1090 \le c_i \le 10^9 ; c11c_1 \ge 1 ).

It can be shown that under these constraints, it is always possible to make a finite amount of turns so that the integers in the cells match the sequence c1,c2,,cnc_1, c_2, \dots, c_n .

Additional constraint on the input: the sum of values of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, print one integer — the minimum number of times Monocarp has to teleport the chip.

输入输出样例

  • 输入#1

    4
    4
    1 2 2 1
    5
    1 0 1 0 1
    5
    5 4 3 2 1
    1
    12

    输出#1

    1
    2
    4
    11

说明/提示

In the first test case of the example, Monocarp can perform the turns as follows:

  • place the chip in the 11 -st cell; the numbers in the cells are [1,0,0,0][1, 0, 0, 0] ;
  • move the chip to the next ( 22 -nd) cell; the numbers in the cells are [1,1,0,0][1, 1, 0, 0] ;
  • move the chip to the next ( 33 -rd) cell; the numbers in the cells are [1,1,1,0][1, 1, 1, 0] ;
  • teleport the chip to the 22 -nd cell; the numbers in the cells are [1,2,1,0][1, 2, 1, 0] ;
  • move the chip to the next ( 33 -rd) cell; the numbers in the cells are [1,2,2,0][1, 2, 2, 0] ;
  • move the chip to the next ( 44 -th) cell; the numbers in the cells are [1,2,2,1][1, 2, 2, 1] .
首页