欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1807G1.Subsequence Addition (Easy Version)
Subsequence Addition (Easy Version)
The only difference between the two versions is that in this version, the constraints are lower.
Initially, array contains just the number . You can perform several operations in order to change the array. In an operation, you can select some subsequence of and add into an element equal to the sum of all elements of the subsequence.
You are given a final array . Check if can be obtained from the initial array by performing some number (possibly 0) of operations on the initial array.
A sequence is a subsequence of a sequence if can be obtained from by the deletion of several (possibly zero, but not all) elements. In other words, select () distinct indices and insert anywhere into a new element with the value equal to .
Input
The first line of the input contains an integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the number of elements the final array should have.
The second line of each test case contains space-separated integers () — the elements of the final array that should be obtained from the initial array .
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output "YES" (without quotes) if such a sequence of operations exists, and "NO" (without quotes) 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
For the first test case, the initial array is already equal to , so the answer is "YES".
For the second test case, performing any amount of operations will change to an array of size at least two which doesn't only have the element , thus obtaining the array is impossible and the answer is "NO".
For the third test case, we can perform the following operations in order to obtain the final given array :
- Initially, .
- By choosing the subsequence , and inserting in the array, changes to .
- By choosing the subsequence , and inserting in the middle of the array, changes to .
- By choosing the subsequence , and inserting after the first of the array, changes to .
- By choosing the subsequence and inserting at the beginning of the array, changes to (which is the array we needed to obtain).
Samples
6
1
1
1
2
5
5 1 3 2 1
5
7 1 5 2 1
3
1 1 1
5
1 1 4 2 1
YES
NO
YES
NO
YES
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |