A11906 | Hills
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Welcome to Innopolis city. Throughout the whole year, Innopolis citizens suffer from everlasting city construction.
From the window in your room, you see the sequence of $n$ hills, where $i$ -th of them has height $a_{i}$ . The Innopolis administration wants to build some houses on the hills. However, for the sake of city appearance, a house can be only built on the hill, which is strictly higher than neighbouring hills (if they are present). For example, if the sequence of heights is $5,4,6,2$ , then houses could be built on hills with heights $5$ and $6$ only.
The Innopolis administration has an excavator, that can decrease the height of an arbitrary hill by one in one hour. The excavator can only work on one hill at a time. It is allowed to decrease hills up to zero height, or even to negative values. Increasing height of any hill is impossible. The city administration wants to build $k$ houses, so there must be at least $k$ hills that satisfy the condition above. What is the minimum time required to adjust the hills to achieve the administration's plan?
However, the exact value of $k$ is not yet determined, so could you please calculate answers for all $k$ in range ? Here  denotes $n$ divided by two, rounded up.
From the window in your room, you see the sequence of $n$ hills, where $i$ -th of them has height $a_{i}$ . The Innopolis administration wants to build some houses on the hills. However, for the sake of city appearance, a house can be only built on the hill, which is strictly higher than neighbouring hills (if they are present). For example, if the sequence of heights is $5,4,6,2$ , then houses could be built on hills with heights $5$ and $6$ only.
The Innopolis administration has an excavator, that can decrease the height of an arbitrary hill by one in one hour. The excavator can only work on one hill at a time. It is allowed to decrease hills up to zero height, or even to negative values. Increasing height of any hill is impossible. The city administration wants to build $k$ houses, so there must be at least $k$ hills that satisfy the condition above. What is the minimum time required to adjust the hills to achieve the administration's plan?
However, the exact value of $k$ is not yet determined, so could you please calculate answers for all $k$ in range ? Here  denotes $n$ divided by two, rounded up.
输入格式
The first line of input contains the only integer $n$ ( $1<=n<=5000$ )—the number of the hills in the sequence.
Second line contains $n$ integers $a_{i}$ ( $1<=a_{i}<=100000$ )—the heights of the hills in the sequence.
Second line contains $n$ integers $a_{i}$ ( $1<=a_{i}<=100000$ )—the heights of the hills in the sequence.
输出格式
Print exactly  numbers separated by spaces. The $i$ -th printed number should be equal to the minimum number of hours required to level hills so it becomes possible to build $i$ houses.
输入输出样例
输入 #1
5 1 1 1 1 1
输出 #1
1 2 2
输入 #2
3 1 2 3
输出 #2
0 2
输入 #3
5 1 2 3 2 2
输出 #3
0 1 3
In the first example, to get at least one hill suitable for construction, one can decrease the second hill by one in one hour, then the sequence of heights becomes $1,0,1,1,1$ and the first hill becomes suitable for construction.
In the first example, to get at least two or at least three suitable hills, one can decrease the second and the fourth hills, then the sequence of heights becomes $1,0,1,0,1$ , and hills $1,3,5$ become suitable for construction.
In the first example, to get at least two or at least three suitable hills, one can decrease the second and the fourth hills, then the sequence of heights becomes $1,0,1,0,1$ , and hills $1,3,5$ become suitable for construction.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted