P26398 [AtCoder] Greedy Customers
提高-
题目描述

Problem Description

In front of Takahashi's shop, there are $ N $ people standing in a single line. The amount of money held by the $ i $-th person from the front is a positive integer $ A_i $.

Takahashi, the shop owner, repeats the following steps: "choose an item and set its price, represented by a positive integer $ P $, and show this item to the people from the front to the back."

In each step, each person will purchase the item if the price $ P $ is less than or equal to their current amount of money. Takahashi's step ends when someone buys the item. That is, the money of the first person with at least $ P $ will decrease by $ P $, and the next step will begin.

Takahashi can independently decide the value of the positive integer $ P $ for each step.

Takahashi wants to sell as many items as possible. However, if a person's money becomes $ 0 $, they cannot go home, which would trouble Takahashi. Therefore, no person's money should be reduced to $ 0 $.

Create a program that, given the initial amounts of money for each person, determines the maximum number of items Takahashi can sell.

Input Format

The input is given from the standard input in the following format:

$ N $ $ A_1 $ : $ A_N $

Output Format

Output an integer representing the maximum number of items Takahashi can sell.

Sample Input and Output

Sample Input #1

3
3
2
5

Sample Output #1

3

Sample Input #2

15
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9

Sample Output #2

18

Notes/Hints

Constraints

  • $1 \leq N \leq 100000$
  • $1 \leq A_i \leq 10^9 (1 \leq i \leq N)$
  • All inputs are integers.

Sample Explanation 1

It is good to choose the values of $ P $ as $ 1, 4, 1 $ in order.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 2 5
样例输出
3