301082: CF205B. Little Elephant and Sorting
Memory Limit:256 MB
Time Limit:0 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Little Elephant and Sorting
题意翻译
给你 $n$ 个数,定义一次操作:任选一个区间 $+1$ ,目的是让后一个数不能小于前一个数(不下降子序列),然后最小操作数是多少?题目描述
The Little Elephant loves sortings. He has an array $ a $ consisting of $ n $ integers. Let's number the array elements from 1 to $ n $ , then the $ i $ -th element will be denoted as $ a_{i} $ . The Little Elephant can make one move to choose an arbitrary pair of integers $ l $ and $ r $ $ (1<=l<=r<=n) $ and increase $ a_{i} $ by $ 1 $ for all $ i $ such that $ l<=i<=r $ . Help the Little Elephant find the minimum number of moves he needs to convert array $ a $ to an arbitrary array sorted in the non-decreasing order. Array $ a $ , consisting of $ n $ elements, is sorted in the non-decreasing order if for any $ i $ $ (1<=i<n) $ $ a_{i}<=a_{i+1} $ holds.输入输出格式
输入格式
The first line contains a single integer $ n $ $ (1<=n<=10^{5}) $ — the size of array $ a $ . The next line contains $ n $ integers, separated by single spaces — array $ a $ $ (1<=a_{i}<=10^{9}) $ . The array elements are listed in the line in the order of their index's increasing.
输出格式
In a single line print a single integer — the answer to the problem. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
输入输出样例
输入样例 #1
3
1 2 3
输出样例 #1
0
输入样例 #2
3
3 2 1
输出样例 #2
2
输入样例 #3
4
7 4 1 47
输出样例 #3
6