CF1392C.Omkar and Waterslide
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Omkar is building a waterslide in his water park, and he needs your help to ensure that he does it as efficiently as possible.
Omkar currently has n supports arranged in a line, the i -th of which has height ai . Omkar wants to build his waterslide from the right to the left, so his supports must be nondecreasing in height in order to support the waterslide. In 1 operation, Omkar can do the following: take any contiguous subsegment of supports which is nondecreasing by heights and add 1 to each of their heights.
Help Omkar find the minimum number of operations he needs to perform to make his supports able to support his waterslide!
An array b is a subsegment of an array c if b can be obtained from c by deletion of several (possibly zero or all) elements from the beginning and several (possibly zero or all) elements from the end.
An array b1,b2,…,bn is called nondecreasing if bi≤bi+1 for every i from 1 to n−1 .
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤100 ). Description of the test cases follows.
The first line of each test case contains an integer n ( 1≤n≤2⋅105 ) — the number of supports Omkar has.
The second line of each test case contains n integers a1,a2,...,an (0≤ai≤109) — the heights of the supports.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, output a single integer — the minimum number of operations Omkar needs to perform to make his supports able to support his waterslide.
输入输出样例
输入#1
3 4 5 3 2 5 5 1 2 3 5 3 3 1 1 1
输出#1
3 2 0
说明/提示
The subarray with which Omkar performs the operation is bolded.
In the first test case:
-
First operation:
[5,3,2,5]→[5,3,3,5]
-
Second operation:
[5,3,3,5]→[5,4,4,5]
-
Third operation:
[5,4,4,5]→[5,5,5,5]
In the third test case, the array is already nondecreasing, so Omkar does 0 operations.