A11092 | Load Testing
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last $n$ minutes and in the $i$ -th minute friends will send $a_{i}$ requests.
Polycarp plans to test Fakebook under a special kind of load. In case the information about Fakebook gets into the mass media, Polycarp hopes for a monotone increase of the load, followed by a monotone decrease of the interest to the service. Polycarp wants to test this form of load.
Your task is to determine how many requests Polycarp must add so that before some moment the load on the server strictly increases and after that moment strictly decreases. Both the increasing part and the decreasing part can be empty (i. e. absent). The decrease should immediately follow the increase. In particular, the load with two equal neigbouring values is unacceptable.
For example, if the load is described with one of the arrays \[1, 2, 8, 4, 3\], \[1, 3, 5\] or \[10\], then such load satisfies Polycarp (in each of the cases there is an increasing part, immediately followed with a decreasing part). If the load is described with one of the arrays \[1, 2, 2, 1\], \[2, 1, 2\] or \[10, 10\], then such load does not satisfy Polycarp.
Help Polycarp to make the minimum number of additional requests, so that the resulting load satisfies Polycarp. He can make any number of additional requests at any minute from $1$ to $n$ .
Polycarp plans to test Fakebook under a special kind of load. In case the information about Fakebook gets into the mass media, Polycarp hopes for a monotone increase of the load, followed by a monotone decrease of the interest to the service. Polycarp wants to test this form of load.
Your task is to determine how many requests Polycarp must add so that before some moment the load on the server strictly increases and after that moment strictly decreases. Both the increasing part and the decreasing part can be empty (i. e. absent). The decrease should immediately follow the increase. In particular, the load with two equal neigbouring values is unacceptable.
For example, if the load is described with one of the arrays \[1, 2, 8, 4, 3\], \[1, 3, 5\] or \[10\], then such load satisfies Polycarp (in each of the cases there is an increasing part, immediately followed with a decreasing part). If the load is described with one of the arrays \[1, 2, 2, 1\], \[2, 1, 2\] or \[10, 10\], then such load does not satisfy Polycarp.
Help Polycarp to make the minimum number of additional requests, so that the resulting load satisfies Polycarp. He can make any number of additional requests at any minute from $1$ to $n$ .
输入格式
The first line contains a single integer $n$ ( $1<=n<=100000$ ) — the duration of the load testing.
The second line contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{9}$ ), where $a_{i}$ is the number of requests from friends in the $i$ -th minute of the load testing.
The second line contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{9}$ ), where $a_{i}$ is the number of requests from friends in the $i$ -th minute of the load testing.
输出格式
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
输入输出样例
输入 #1
5 1 4 3 2 5
输出 #1
6
输入 #2
5 1 2 2 2 1
输出 #2
1
输入 #3
7 10 20 40 50 70 90 30
输出 #3
0
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: \[1, 4, 5, 6, 5\]. In total, Polycarp will make $6$ additional requests.
In the second example it is enough to make one additional request in the third minute, so the answer is $1$ .
In the third example the load already satisfies all conditions described in the statement, so the answer is $0$ .
In the second example it is enough to make one additional request in the third minute, so the answer is $1$ .
In the third example the load already satisfies all conditions described in the statement, so the answer is $0$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted