309914: CF1759B. Lost Permutation

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Lost Permutation

题意翻译

共 $t$ 组输入。 对于每组输入,第一行是 $m,s$,第二行是 $b_1,b_2,\dots,b_m$。 已知原数组 $a_1,a_2,\dots,a_n$ 是 $1\sim n$ 的一个排列。现在去掉的一些数,变成了 $b_1,b_2,\dots,b_m$,去掉的数字的和为 $s$。问能否求出一个 $a$(能则 `YES`,否则 `NO`,大小写不敏感)。 Translated by @_JYqwq_

题目描述

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?

输入输出格式

输入格式


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.

输出格式


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).

输入输出样例

输入样例 #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.

Input

题意翻译

共 $t$ 组输入。 对于每组输入,第一行是 $m,s$,第二行是 $b_1,b_2,\dots,b_m$。 已知原数组 $a_1,a_2,\dots,a_n$ 是 $1\sim n$ 的一个排列。现在去掉的一些数,变成了 $b_1,b_2,\dots,b_m$,去掉的数字的和为 $s$。问能否求出一个 $a$(能则 `YES`,否则 `NO`,大小写不敏感)。 Translated by @_JYqwq_

Output

题目大意:
给定一个序列,判断是否能通过添加一些数字使其成为一个排列。已知原数组是1到n的一个排列,现在去掉了一些数,变成了b1,b2,…,bm,去掉的数字的和为s。问能否求出一个a(能则YES,否则NO,大小写不敏感)。

输入输出数据格式:
输入格式:
第一行包含一个整数t(1≤t≤100)——测试用例的数量。
接下来是t个测试用例的描述。
每个测试用例的第一行包含两个整数m和s(1≤m≤50,1≤s≤1000)——找到的元素数量和遗忘的数字之和。
每个测试用例的第二行包含m个不同的整数b1,b2…bm(1≤bi≤50)——Polycarp找到的元素。

输出格式:
输出t行,每行是对应测试用例的答案。如果可以通过添加几个元素到数组b,使得它们的和等于s,并且结果是一个排列,则输出YES。否则输出NO。

输入输出样例:
输入样例#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题目大意: 给定一个序列,判断是否能通过添加一些数字使其成为一个排列。已知原数组是1到n的一个排列,现在去掉了一些数,变成了b1,b2,…,bm,去掉的数字的和为s。问能否求出一个a(能则YES,否则NO,大小写不敏感)。 输入输出数据格式: 输入格式: 第一行包含一个整数t(1≤t≤100)——测试用例的数量。 接下来是t个测试用例的描述。 每个测试用例的第一行包含两个整数m和s(1≤m≤50,1≤s≤1000)——找到的元素数量和遗忘的数字之和。 每个测试用例的第二行包含m个不同的整数b1,b2…bm(1≤bi≤50)——Polycarp找到的元素。 输出格式: 输出t行,每行是对应测试用例的答案。如果可以通过添加几个元素到数组b,使得它们的和等于s,并且结果是一个排列,则输出YES。否则输出NO。 输入输出样例: 输入样例#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

加入题单

算法标签: