#P2816. Stacking Blocks
Stacking Blocks
Stacking Blocks
Saruka loves building blocks. He has n blocks, each with a special emotion value denoted by \(x_i\) (using LaTeX format). These blocks are very clever and can only be stacked vertically in columns. When a block is placed in a column, the number of blocks above it will be counted. For the block with emotion value \(x_i\), if the number of blocks placed above it becomes greater than \(x_i\), then that block will be unhappy and will refuse to play further.
Saruka, who loves his blocks very much, wants to make sure that every block is used and no block becomes unhappy. At the same time, he wishes to use as few columns as possible. Your task is to help him determine the minimum number of columns required so that, if the blocks in each column are rearranged optimally (with the top block counting \(0\) and each block below counting the number of blocks above it), every block \(i\) satisfies its condition:
[ \text{number of blocks above block } i \leq x_i ]
Hint: It is optimal to sort the blocks by their emotion values and then assign each block to an existing column if possible, or create a new column if necessary.
inputFormat
The first line of input contains an integer \(n\) representing the number of blocks. The second line contains \(n\) space-separated non-negative integers \(x_1, x_2, \dots, x_n\), where \(x_i\) is the emotion value of the \(i\)-th block.
outputFormat
Output a single integer, the minimum number of columns needed to stack all blocks without making any block unhappy.
sample
5
0 0 0 0 0
5