#K92417. Minimum Increments to Achieve Non-Decreasing Tax Collection
Minimum Increments to Achieve Non-Decreasing Tax Collection
Minimum Increments to Achieve Non-Decreasing Tax Collection
You are given a sequence of tax amounts collected from a row of houses. Your task is to ensure that the tax amount is non-decreasing along the houses (i.e., for every (i) ((1 \leq i < n)), the tax at house (i+1) should be at least the tax at house (i)). To achieve this, you are only allowed to increment the tax amount at any house. Find the minimum total number of increments needed to make the sequence non-decreasing.
Formally, given an array (T) of length (n), compute the minimum total increments so that for all (i) from 1 to (n-1), (T[i] \ge T[i-1]). You may increase (T[i]) by 1 in each increment operation.
inputFormat
The input is given via standard input (stdin). The first line contains an integer (n) representing the number of houses. The second line contains (n) space-separated integers, where each integer denotes the tax amount at a house.
outputFormat
Output a single integer to standard output (stdout) representing the minimum number of increments required to make the tax collection sequence non-decreasing.## sample
4
4 2 3 5
3