#C9311. Balanced Plant Arrangement
Balanced Plant Arrangement
Balanced Plant Arrangement
You are given n plants, each with a watering requirement represented by an integer. Your task is to determine whether it is possible to rearrange the watering requirements so that the absolute difference between any two consecutive watering values is at most 1. In other words, after sorting the list in non-decreasing order, the condition to satisfy is:
\( |a_{i} - a_{i+1}| \leq 1 \) for every \( 1 \leq i \lt n \).
If the condition holds, print Yes
; otherwise, print No
.
inputFormat
The input is read from stdin and consists of:
- An integer
n
(\(1 \leq n \leq 10^5\)), the number of plants. - A sequence of
n
integers representing the watering requirements, separated by spaces.
outputFormat
Output a single line to stdout containing Yes
if the watering requirements can be rearranged to form a balanced pattern under the given condition, and No
otherwise.
5
3 1 2 2 1
Yes