#K11881. Minimum Visible Blocks

    ID: 23567 Type: Default 1000ms 256MiB

Minimum Visible Blocks

Minimum Visible Blocks

You are given a list of integers representing the heights of people. Your task is to arrange these people into groups (blocks) such that each block contains people whose heights differ by at most 1 unit. Formally, if the current block has a minimum height h, then another person with height h' can join the block if and only if \( h' \leq h+1 \).

You need to determine the minimum number of such blocks required to cover all people. The procedure is as follows: sort the list of heights, initialize the first block with the smallest height, then for every height \( h_i \) in the sorted order, if \( h_i > current\_block + 1 \) (i.e. \( h_i > current\_block + 1 \)), start a new block and update the current block minimum value.

Example: For the input array [1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 2, 1], after sorting it becomes [1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5]. There are three blocks: one for heights around 1 and 2, one for heights around 3 and 4, and one for heights around 5.

inputFormat

The input is read from standard input (stdin) and consists of two lines. The first line contains a single integer ( n ) indicating the number of people. The second line contains ( n ) space-separated integers representing the heights of the people.

outputFormat

Output a single integer to standard output (stdout) representing the minimum number of visible blocks required.## sample

12
1 2 3 4 5 5 4 4 3 3 2 1
3