← 返回 capitalone 的题目列表Minimum Increment Operations to Make Heights Strictly +/-1 Monotonic
类型:online_judge
Given an integer array nums representing house heights from left to right, one operation increments any single element by 1.
Make the final array satisfy either:
strictly increasing with adjacent difference 1: [a, a+1, ..., a+n-1], or
strictly decreasing with adjacent difference 1: [b, b-1, ..., b-(n-1)].
Only increments are allowed (no decrements). Return the minimum number of operations needed to reach either form.
Input
Line 1: integer n
Line 2: n integers nums
Output
The minimum number of increment operations.
Constraints
1 <= n <= 2e5
-1e9 <= nums[i] <= 1e9
Example
Input
3
1 1 1
Output
3