#C2832. Booth Rearrangement
Booth Rearrangement
Booth Rearrangement
Problem Statement: You are given n booths, each selling items of a particular category represented by an integer. Your task is to rearrange the booths so that no two adjacent booths sell items of the same category. A rearrangement is possible if and only if the highest frequency of any category does not exceed \(\lceil \frac{n}{2} \rceil\). If a valid rearrangement exists, output "Yes" followed by a valid arrangement; otherwise, output "No".
inputFormat
Input Format:
- The first line contains an integer n, the number of booths.
- The second line contains n space-separated integers, where each integer represents a booth's category.
outputFormat
Output Format:
- If a valid rearrangement exists, print "Yes" on the first line and on the second line print n space-separated integers representing one valid booth arrangement.
- If no valid rearrangement exists, print a single line containing "No".
4
1 2 3 4
Yes
1 2 3 4
</p>