Problem G: 吃苹果

Problem G: 吃苹果

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

有 lns="http://www.w3.org/1998/Math/MathML">n 只苹果,第 lns="http://www.w3.org/1998/Math/MathML">i 只苹果的保质期为 lns="http://www.w3.org/1998/Math/MathML">ai 天,若 lns="http://www.w3.org/1998/Math/MathML">ai=0 意味着它必须在第一天吃掉,不然就变质了,若 lns="http://www.w3.org/1998/Math/MathML">ai>0 意味着它可以保存 lns="http://www.w3.org/1998/Math/MathML">ai 天。

每天只能吃一只苹果,应该如何安排,使得吃掉的苹果最多?

Input

  • 第一行:单个整数 lns="http://www.w3.org/1998/Math/MathML">n
  • 第二行:lns="http://www.w3.org/1998/Math/MathML">n 个整数 lns="http://www.w3.org/1998/Math/MathML">a1,a2,,an
  • 对于 lns="http://www.w3.org/1998/Math/MathML">30% 的数据,lns="http://www.w3.org/1998/Math/MathML">1n10
  • 对于 lns="http://www.w3.org/1998/Math/MathML">60% 的数据,lns="http://www.w3.org/1998/Math/MathML">1n1,000
  • 对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,lns="http://www.w3.org/1998/Math/MathML">1n1,000,000lns="http://www.w3.org/1998/Math/MathML">0ain

Output

  • 单个整数:表示能够吃掉的最多的苹果数。

Sample Input Copy

5
4 1 0 2 1

Sample Output Copy

4