A15521 | Lost Permutation
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A sequence of $n$ numbers is called a permutation if it contains all integers from $1$ to $n$ exactly once. For example, the sequences \[ $3, 1, 4, 2$ \], \[ $1$ \] and \[ $2,1$ \] are permutations, but \[ $1,2,1$ \], \[ $0,1$ \] and \[ $1,3,4$ \] — are not.
Polycarp lost his favorite permutation and found only some of its elements — the numbers $b_1, b_2, \dots b_m$ . He is sure that the sum of the lost elements equals $s$ .
Determine whether one or more numbers can be appended to the given sequence $b_1, b_2, \dots b_m$ such that the sum of the added numbers equals $s$ , and the resulting new array is a permutation?
Polycarp lost his favorite permutation and found only some of its elements — the numbers $b_1, b_2, \dots b_m$ . He is sure that the sum of the lost elements equals $s$ .
Determine whether one or more numbers can be appended to the given sequence $b_1, b_2, \dots b_m$ such that the sum of the added numbers equals $s$ , and the resulting new array is a permutation?
输入格式
The first line of input contains a single integer $t$ ( $1 \le t \le 100$ ) —the number of test cases.
Then the descriptions of the test cases follow.
The first line of each test set contains two integers $m$ and $s$ ( $1 \le m \le 50$ , $1 \le s \le 1000$ )—-the number of found elements and the sum of forgotten numbers.
The second line of each test set contains $m$ different integers $b_1, b_2 \dots b_m$ ( $1 \le b_i \le 50$ ) — the elements Polycarp managed to find.
Then the descriptions of the test cases follow.
The first line of each test set contains two integers $m$ and $s$ ( $1 \le m \le 50$ , $1 \le s \le 1000$ )—-the number of found elements and the sum of forgotten numbers.
The second line of each test set contains $m$ different integers $b_1, b_2 \dots b_m$ ( $1 \le b_i \le 50$ ) — the elements Polycarp managed to find.
输出格式
Print $t$ lines, each of which is the answer to the corresponding test set. Print as the answer YES if you can append several elements to the array $b$ , that their sum equals $s$ and the result will be a permutation. Output NO otherwise.
You can output the answer in any case (for example, yEs, yes, Yes and YES will be recognized as positive answer).
You can output the answer in any case (for example, yEs, yes, Yes and YES will be recognized as positive answer).
输入输出样例
输入 #1
5 3 13 3 1 4 1 1 1 3 3 1 4 2 2 1 4 3 5 6 1 2 3 4 5
输出 #1
YES NO YES NO YES
In the test case of the example, $m=3, s=13, b=[3,1,4]$ . You can append to $b$ the numbers $6,2,5$ , the sum of which is $6+2+5=13$ . Note that the final array will become $[3,1,4,6,2,5]$ , which is a permutation.
In the second test case of the example, $m=1, s=1, b=[1]$ . You cannot append one or more numbers to $[1]$ such that their sum equals $1$ and the result is a permutation.
In the third test case of the example, $m=3, s=3, b=[1,4,2]$ . You can append the number $3$ to $b$ . Note that the resulting array will be $[1,4,2,3]$ , which is a permutation.
In the second test case of the example, $m=1, s=1, b=[1]$ . You cannot append one or more numbers to $[1]$ such that their sum equals $1$ and the result is a permutation.
In the third test case of the example, $m=3, s=3, b=[1,4,2]$ . You can append the number $3$ to $b$ . Note that the resulting array will be $[1,4,2,3]$ , which is a permutation.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted