#C2063. Minimum Moves to Non-decreasing Array

    ID: 45338 Type: Default 1000ms 256MiB

Minimum Moves to Non-decreasing Array

Minimum Moves to Non-decreasing Array

Given an array of integers, determine the minimum number of moves required to make the array non-decreasing. In one move, you can increase an element to match the value of its preceding element if it is smaller. Formally, for an array a = [a1, a2, ..., an], you need to perform the minimum total increment operations so that ai ≥ ai-1 for all 2 ≤ i ≤ n.

For example, for the array [3, 2, 1], the minimum moves required is 3: increase 2 to 3 (1 move) and then increase 1 to 3 (2 moves).

This problem will have multiple test cases. You are required to process each test case individually.

inputFormat

The first line of input contains an integer T, the number of test cases. Each test case consists of two lines:

  • The first line contains an integer n, the number of elements in the array.
  • The second line contains n space-separated integers representing the elements of the array.

outputFormat

For each test case, output a single line containing one integer: the minimum number of moves required to make the array non-decreasing.

## sample
4
3
3 2 1
4
1 5 3 4
2
10 10
5
1 2 3 4 5
3

3 0 0

</p>