A10473 | Sonya and Problem Wihtout a Legend
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
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$ .
输入格式
The first line of the input contains a single integer $n$ ( $1<=n<=3000$ ) — the length of the array.
Next line contains $n$ integer $a_{i}$ ( $1<=a_{i}<=10^{9}$ ).
Next line contains $n$ integer $a_{i}$ ( $1<=a_{i}<=10^{9}$ ).
输出格式
Print the minimum number of operation required to make the array strictly increasing.
输入输出样例
输入 #1
7 2 1 5 11 5 9 11
输出 #1
9
输入 #2
5 5 4 3 2 1
输出 #2
12
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|+|11-6|+|5-7|+|9-9|+|11-11|=9$
And for the second sample:
$1$ $2$ $3$ $4$ $5$
$|5-1|+|4-2|+|3-3|+|2-4|+|1-5|=12$
$2$ $3$ $5$ $6$ $7$ $9$ $11$
$|2-2|+|1-3|+|5-5|+|11-6|+|5-7|+|9-9|+|11-11|=9$
And for the second sample:
$1$ $2$ $3$ $4$ $5$
$|5-1|+|4-2|+|3-3|+|2-4|+|1-5|=12$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted