QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#18591. Factorial Attack

통계

There are $N$ monsters standing in a row on a field. The health of the $i$-th monster is $h_i$.

You must defeat all the monsters on the field. To defeat a monster, you must reduce its health to $0$ or less.

To defeat the monsters, you can choose two integers $l \le r$ and cast an area-of-effect attack on the monsters from the $l$-th to the $r$-th position.

Monsters hit by this area-of-effect attack have their health reduced by $(N - r + l)!$.

Find the minimum number of area-of-effect attacks required to defeat all monsters.

$n!$ is the product of all integers from $1$ to $n$.

Input

The first line contains an integer $N$. $(1 \le N \le 500)$

The second line contains $h_1, h_2, \ldots, h_N$ separated by spaces. $(1 \le h_i \le 5000)$

Output

The first line outputs the minimum number of area-of-effect attacks required to defeat all monsters.

Examples

Input 1

4
1 2 3 4

Output 1

2

Input 2

1
5000

Output 2

5000

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.