#CODEFORCESP331. Make It Increasing

    ID: 240 远端评测题 2000ms 256MiB 尝试: 60 已通过: 1 难度: 10 上传者: 标签>binary searchconstructive algorithmsdata structuresdpimplementation*2200

Make It Increasing

Make it Increasing

题面翻译

题目描述

给定一个包含 nn正整数的数列 aa 以及一个长度为 nn 的数列 bb ,初始时数列 bb 的每一个元素都为0。定义一次操作为把数列 bb 中的某个元素 bib_i 加上或减去 aia_i 的值,求使得数列 bb 严格递增最小的操作次数。

输入格式

第一行为一个整数 nn (2n5000)(2 \le n \le 5000),第二行为 nn 个正整数,a1a_1 , a2a_2 , ... , ana_n (1ai109)(1 \le a_i \le {10}^9) ,作为数列 aa 的值。

输出格式

输出使数列 bb 严格递增的最小操作次数。

题目描述

You are given an array a a consisting of n n positive integers, and an array b b , with length n n . Initially bi=0 b_i=0 for each 1in 1 \leq i \leq n .

In one move you can choose an integer i i ( 1in 1 \leq i \leq n ), and add ai a_i to bi b_i or subtract ai a_i from bi b_i . What is the minimum number of moves needed to make b b increasing (that is, every element is strictly greater than every element before it)?

输入格式

The first line contains a single integer n n ( 2n5000 2 \leq n \leq 5000 ).

The second line contains n n integers, a1 a_1 , a2 a_2 , ..., an a_n ( 1ai109 1 \leq a_i \leq 10^9 ) — the elements of the array a a .

输出格式

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

样例 #1

样例输入 #1

5
1 2 3 4 5

样例输出 #1

4

样例 #2

样例输入 #2

7
1 2 1 2 1 2 1

样例输出 #2

10

样例 #3

样例输入 #3

8
1 8 2 7 3 6 4 5

样例输出 #3

16

提示

Example 1 1 : you can subtract a1 a_1 from b1 b_1 , and add a3 a_3 , a4 a_4 , and a5 a_5 to b3 b_3 , b4 b_4 , and b5 b_5 respectively. The final array will be [ 1 -1 , 0 0 , 3 3 , 4 4 , 5 5 ] after 4 4 moves.

Example 2 2 : you can reach [ 3 -3 , 2 -2 , 1 -1 , 0 0 , 1 1 , 2 2 , 3 3 ] in 10 10 moves.