欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1660B.Vlad and Candies
Vlad and Candies
Not so long ago, Vlad had a birthday, for which he was presented with a package of candies. There were types of candies, there are candies of the type ().
Vlad decided to eat exactly one candy every time, choosing any of the candies of a type that is currently the most frequent (if there are several such types, he can choose any of them). To get the maximum pleasure from eating, Vlad does not want to eat two candies of the same type in a row.
Help him figure out if he can eat all the candies without eating two identical candies in a row.
Input
The first line of input data contains an integer () — the number of input test cases.
The following is a description of test cases of input, two lines for each.
The first line of the case contains the single number () — the number of types of candies in the package.
The second line of the case contains integers () — the number of candies of the type .
It is guaranteed that the sum of for all cases does not exceed .
Output
Output lines, each of which contains the answer to the corresponding test case of input. As an answer, output "YES" if Vlad can eat candy as planned, and "NO" otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
Note
In the first example, it is necessary to eat sweets in this order:
- a candy of the type , it is the most frequent, now ;
- a candy of the type , there are the same number of candies of the type , but we just ate one, now ;
- a candy of the type , it is the most frequent, now ;
- a candy of the type , now ;
- a candy of the type , now and the candy has run out.
In the second example, all the candies are of the same type and it is impossible to eat them without eating two identical ones in a row.
In the third example, first of all, a candy of the type will be eaten, after which this kind will remain the only kind that is the most frequent, and you will have to eat a candy of the type again.
Samples
6
2
2 3
1
2
5
1 6 2 4 3
4
2 2 2 1
3
1 1000000000 999999999
1
1
YES
NO
NO
YES
YES
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |