Sonya and A Problem without A Legend(DP+优化)

给定一个包含正整数的数组,每次操作可以选择一个元素增加或减少1,目标是通过最少的操作次数使数组变得严格递增。输入包含数组长度和数组元素,输出需要的最小操作数。通过动态规划和优化方法可以解决此问题,记录上一层的最小值来减少计算量。
摘要由CSDN通过智能技术生成

Sonya was unable to think of a story for this problem, so here comes the formal description.

You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0.

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 3000) — the length of the array.

Next line contains n integer ai (1 ≤ ai ≤ 109).

Output
Print the minimum number of operation required to make the array strictly increasing.

Example
Input
7
2 1 5 11 5 9 11
Output
9
Input
5
5 4 3 2 1
Output
12
Note
In the first sample, the array is going to look as follows:

2 3 5 6 7 9 11

|2 - 2| + |1 - 3| + |5 - 5| &#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值