| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 512 MB | 91 | 46 | 42 | 57.534% |
Mila likes to play Tetris. Today she learnt about a new game that is similar to Tetris. The new game has an infinite rectangular field with the bottom and width equal to $n,ドル divided into cells of size 1ドル \times 1$. Unlike real Tetris in this game horizontal pieces with height 1ドル$ and width $x$ consisting of $x$ cells --- of size 1ドル \times x,ドル are used. Before the next piece starts to fall, a player can choose it's size $x$ as any integer between 1ドル$ and $n,ドル inclusive. Pieces can't be rotated, but they can be moved left or right. A piece falls until it reaches an occupied cell under it or the bottom of the field.
Mile doesn't like to leave empty cells under the pieces. Her goal is to fill lower rows of the field in the way that all occupied cells form a rectangle of width $n$.
You are given a field state: $a_1, a_2, \ldots, a_n,ドル where $a_i$ --- the number of occupied cells in the $i$-th column of the field. In the given field no empty cell is under the occupied one. For example, if sequence $a$ is 3,ドル 2, 4, 2, 2, 4,ドル the field looks like this:
Find the minimum number of pieces Mila needs to play to occupy the lower rows of the field forming a rectangle of width $n$.
The first line contains a single integer $n$ --- the width of the field (1ドル \le n \le 2 \cdot 10^5$).
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ --- the number of occupied cells in each column of the field (0ドル \le a_i \le 10^9$).
At least on of the $a_i$ is strictly greater than 0ドル$.
Print a single integer: the minimum number of pieces Mila will need to build a rectangle of width $n$.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 8 | $n \le 10,ドル $a_i \le 5$ |
| 2 | 13 | $n \le 100,ドル $a_i \le 500$ |
| 3 | 16 | $n \le 1000,ドル $a_i \le 5000$ |
| 4 | 17 | $n \le 1000,ドル $a_i \le 10^9$ |
| 5 | 25 | $n \le 10^5,ドル $a_i \le 10^9,ドル when $n > 1000$ sequence $a$ is generated randomly |
| 6 | 21 | $n \le 2 \cdot 10^5,ドル $a_i \le 10^9$ |
6 3 2 4 2 2 4
4
In the example Mile can use the following four pieces: