#P10922. HappyBob's Number Deletion

    ID: 12969 Type: Default 1000ms 256MiB

HappyBob's Number Deletion

HappyBob's Number Deletion

HappyBob has n numbers on the ground, denoted by $a_i$ for $1\le i\le n$. Before starting his deletion process, he may rearrange these numbers in any order of his choice.

After rearrangement, he performs the deletion process repeatedly as follows:

  1. Initialize a deletion index $h=1$.
  2. Set $H=a_h$. Then, for every integer $i$ satisfying $h \le i < k$ (where $k$ is the current count of numbers on the ground), update $a_i \gets a_{i+1}$ and then delete $a_k$ (the last number).
  3. Set $h=H$.

The process stops after an operation if the new value of $h$ is strictly greater than the current number of numbers remaining.

Note that not all numbers may be deleted using this procedure. Your task is to determine the maximum number of deletion operations HappyBob can perform by choosing an optimal rearrangement of the original numbers.

Observation: The first deletion always occurs. However, to perform a subsequent (i.e. the $i$-th) deletion for $i\ge2$, the number used in the $(i-1)$-th operation (i.e. the value $H$) must be at most $n-(i-1)$ (since after each deletion the number of remaining elements decreases by one). Thus, if we denote by $x_1,x_2,\dots,x_{t}$ the sequence of numbers selected in each deletion (with $x_1$ chosen arbitrarily because the first deletion always happens), then for maximum deletions we must have \[ x_i \le n-i, \quad \text{for } i=1,2,\dots,t-1. \] The goal is to maximize $t$, and you are allowed to reorder the array arbitrarily to achieve this.

inputFormat

The first line contains a single integer $n$ ($1\le n\le 10^5$) — the number of numbers on the ground. The second line contains $n$ space-separated integers $a_1,a_2,\dots,a_n$ ($1\le a_i\le 10^9$).

outputFormat

Output a single integer — the maximum number of deletion operations HappyBob can perform.

sample

3
1 1 1
3