increasing-array

Table of Contents

Array"

Increasing Array

Prev: [repetitions](repetitions.html) Next: [permutations](permutations.html)

You are given an array of n integers. You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element.

On each move, you may increase the value of any element by one. What is the minimum number of moves required?

Input

The first input line contains an integer n: the size of the array.

Then, the second line contains n integers x1,x2,...,xn: the contents of the array.

Increasing Array

{{# include _include/code/algorithms/cses/cpp/introductory/increasing-array.cc }}

Prev: [repetitions](repetitions.html) Next: [permutations](permutations.html)