CF1392C-Omkar and Waterslide
CF1392C-Omkar and Waterslide
题目:
题目描述:
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 supports arranged in a line, the -th of which has height . 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 operation, Omkar can do the following: take any contiguous subsegment of supports which is nondecreasing by heights and add 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 is a subsegment of an array if can be obtained from by deletion of several (possibly zero or all) elements from the beginning and several (possibly zero or all) elements from the end.
An array is called nondecreasing if for every from to .
输入格式:
Each test contains multiple test cases. The first line contains the number of test cases ( ). Description of the test cases follows.
The first line of each test case contains an integer ( ) — the number of supports Omkar has.
The second line of each test case contains integers — the heights of the supports.
It is guaranteed that the sum of over all test cases does not exceed .
输出格式:
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:
|
|
样例输出1:
|
|
思路:
实现:
|
|
v1.4.14