#GD0000187. Vlad và những viên kẹo (Vlad and Candies)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Vlad và những viên kẹo (Vlad and Candies)
Vlad and Candies
Source: Codeforces
Version: Phuoc Hung OJ (single-case adaptation where applicable)
Problem Statement
Vlad has types of candy, with candies of type . On each move he must eat one candy of a currently most frequent type; ties can be broken arbitrarily. He wants to eat all candies without taking the same type on two consecutive moves. Determine whether this is possible.
Input
Line 1 contains . Line 2 contains exactly positive integers .
Output
Print YES if such an eating order exists; otherwise print NO.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Example 1
Input
2
2 3
Output
YES
Explanation
Type 2 has three candies and is selected first. Then the two types can alternate until all candies are consumed.
Example 2
Input
3
1 4 1
Output
NO
Explanation
The most frequent type has four candies, exceeding the second largest count by three; after eating one, it remains the unique maximum and would have to be selected again.