欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2124A.Deranged Deletions
Deranged Deletions
Call an array of length a derangement if the following property holds:
- Let be an array of length such that over all .
- Sort in non-decreasing order.
- If over all , then is a derangement.
For example,
- If , then after getting sorted. Since in all positions, is a derangement.
- If , then after getting sorted. Since , is not a derangement.
You are given an array of length . In one operation, you can delete an element from . The order of the remaining elements is preserved after each deletion.
Output whether it is possible to perform some (possibly none) operations such that the remaining elements form a derangement. If it is possible, output any possible remaining array. The remaining array must be non-empty.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains an integer () — the length of array .
The second line of each test case contains integers () — denoting the array .
Output
For each test case, on a new line, if it is possible to perform operations such that the remaining array is a derangement, output YES. Otherwise, output NO.
You can output in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
If your response was positive, output two more lines in the following format:
- The first line should contain an integer (), the number of elements that remain in the array.
- The second line should contain , the elements that remain in the array. It must be possible to acquire array after performing some operations on . Array must be a derangement.
Note
In the second test case, we can delete one from the array so that it becomes . It can be shown this array is a derangement. This is not the only solution – it can be shown that the original array is another valid solution.
Samples
3
3
2 2 3
5
4 5 5 2 4
1
1
NO
YES
4
4 5 2 4
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |