#K91892. Minimum Steps to Non-Decreasing Array
Minimum Steps to Non-Decreasing Array
Minimum Steps to Non-Decreasing Array
You are given an array of integers. Your task is to determine the minimum number of steps required to convert the array into a non-decreasing array. In each step, you may increment any element in the array by 1.
An array \( a_1, a_2, \dots, a_n \) is said to be non-decreasing if it satisfies the condition \( a_1 \le a_2 \le \dots \le a_n \).
For example, consider the array [1, 2, 1]. In order to make this array non-decreasing, you can increment the third element from 1 to 2. Hence, the minimum number of steps required is 1.
You are required to process multiple test cases.
inputFormat
The first line of the input contains an integer ( T ) representing the number of test cases. For each test case, the first line contains a positive integer ( n ) denoting the number of elements in the array, followed by a line containing ( n ) space-separated integers representing the array elements.
outputFormat
For each test case, output a single line containing the minimum number of steps required to make the array non-decreasing.## sample
1
3
1 2 1
1
</p>