A. Make it Increasing-Codeforces Round #783 (Div. 1)

Problem - 1667A - Codeforces

A. Make it Increasing

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array aa consisting of nn positive integers, and an array bb, with length nn. Initially bi=0bi=0 for each 1≤i≤n1≤i≤n.

In one move you can choose an integer ii (1≤i≤n1≤i≤n), and add aiai to bibi or subtract aiai from bibi. What is the minimum number of moves needed to make bb increasing (that is, every element is strictly greater than every element before it)?

Input

The first line contains a single integer nn (2≤n≤50002≤n≤5000).

The second line contains nn integers, a1a1, a2a2, ..., anan (1≤ai≤1091≤ai≤109) — the elements of the array aa.

Output

Print a single integer, the minimum number of moves to make bb increasing.

Examples

input

Copy

5
1 2 3 4 5

output

Copy

4

input

Copy

7
1 2 1 2 1 2 1

output

Copy

10

input

Copy

8
1 8 2 7 3 6 4 5

output

Copy

16

Note

Example 11: you can subtract a1a1 from b1b1, and add a3a3, a4a4, and a5a5 to b3b3, b4b4, and b5b5 respectively. The final array will be [−1−1, 00, 33, 44, 55] after 44 moves.

Example 22: you can reach [−3−3, −2−2, −1−1, 00, 11, 22, 33] in 1010 moves.

观察样例易知,必定要有一个是0的位置,所以又根据数据范围5000推测n^2算法,故可以枚举0位置左右n扩展,求出最小值即可

# include<iostream>
# include<vector>
# include<cstring>
# include<map>
# include<algorithm>
# define mod 1000000007
using namespace std;
typedef long long int ll;

ll a[10000];

int main ()
{


    int n;

    cin>>n;

    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }

    ll ans=0x7f7ff7f7f7f;


    for(int i=1;i<=n;i++)
    {

        ll temp=0;

        ll pre=0;

        for(int j=i-1;j>=1;j--)
        {
            temp+=(abs(pre)/(abs(a[j])))+1;

            pre=((abs(pre)/(abs(a[j])))+1)*abs(a[j]);

        }

        pre=0;

        for(int j=i+1;j<=n;j++)
        {
            temp+=(abs(pre)/(abs(a[j])))+1;

            pre=((abs(pre)/(abs(a[j])))+1)*abs(a[j]);

        }

        ans=min(ans,temp);

    }

    cout<<ans;

    return 0;

}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秦三码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值