QOJ.ac

QOJ

时间限制: 1 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#18591. Factorial Attack

统计

필드에 $N$마리의 몬스터가 일렬로 서 있다. $i$번째 몬스터의 체력은 $h_i$이다.

당신은 필드의 모든 몬스터를 처치해야 한다. 몬스터를 처치하기 위해서는 해당 몬스터의 체력을 $0$ 이하로 만들어야 한다.

몬스터를 처치하기 위해 당신은 두 정수 $l \le r$을 골라 $l$번째부터 $r$번째까지의 몬스터에게 범위 공격을 시전할 수 있다.

이 범위 공격을 맞은 몬스터는 체력이 $(N - r + l)!$만큼 감소한다.

모든 몬스터를 처치하기 위해 최소 몇 번의 범위 공격을 시전해야 하는지 구하시오.

$n!$은 $1$부터 $n$까지의 모든 정수를 곱한 값이다.

Input

첫 번째 줄에 정수 $N$이 주어진다. $(1 \le N \le 500)$

두 번째 줄에 $h_1, h_2, \ldots, h_N$이 공백으로 구분되어 주어진다. $(1 \le h_i \le 5000)$

Output

첫 번째 줄에 모든 몬스터를 처치하기 위해 시전해야 하는 범위 공격의 최소 횟수를 출력한다.

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.