#K55102. Basket Arrangement Problem
Basket Arrangement Problem
Basket Arrangement Problem
You are given several datasets representing groups of colored bamboo strips. In each dataset, the first number n denotes the number of different color groups, followed by n integers representing the count of strips in each color group. Your task is to determine whether it is possible to arrange the baskets made from bamboo strips so that no two adjacent baskets contain the same predominant color. The arrangement is possible if the maximum count among the groups does not exceed \(\frac{\text{total strips} + 1}{2}\) (i.e. \(\max \le \lceil\frac{total}{2}\rceil\)).
The input terminates with a dataset starting with a 0 (which should not be processed).
inputFormat
The input is given from standard input (stdin) and consists of several lines. Each dataset is on its own line. A dataset starts with an integer n (the number of different colors), followed by n positive integers describing the count of bamboo strips in that group. The end of input is indicated by a line starting with a 0.
Example:
3 3 3 3 4 7 3 5 2 2 1 100 0
outputFormat
For each dataset (except the terminating one), output a single line to standard output (stdout) containing either "Yes" if it is possible to arrange the baskets as desired, or "No" otherwise.
Example:
Yes Yes No## sample
3 3 3 3
4 7 3 5 2
2 1 100
0
Yes
Yes
No
</p>