#C11000. Match Scheduling for School Teams
Match Scheduling for School Teams
Match Scheduling for School Teams
You are given several test cases. In each test case, there are teams from different schools. For each test case, the first line contains an integer N which represents the number of schools. The second line contains N integers, where the i-th integer represents the number of teams from the i-th school.
Your task is to determine whether it is possible to schedule the matches in the first round such that no two teams from the same school compete against each other.
The underlying idea is based on a necessary condition that the school with the maximum number of teams does not overwhelm the others. In particular, if we denote by \(max\) the maximum number of teams from any school and by \(total\) the total number of teams, then a valid schedule exists if and only if
\( max \leq total - max + 1 \)
If the condition holds, output Yes
; otherwise, output No
for that test case.
inputFormat
The input begins with a single integer T
(1 ≤ T ≤ 10), the number of test cases. For each test case:
- The first line contains an integer
N
(1 ≤ N ≤ 105), the number of schools. - The second line contains
N
space-separated integers, where the i-th integer is the number of teams from the i-th school.
It is guaranteed that the total number of teams across all test cases does not exceed 106.
outputFormat
For each test case, output a single line containing either Yes
if it is possible to schedule the matches without having two teams from the same school in one match, or No
otherwise.
3
2
2 3
3
1 2 2
1
4
Yes
Yes
No
</p>