CF1759B.Lost Permutation

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A sequence of nn numbers is called a permutation if it contains all integers from 11 to nn exactly once. For example, the sequences [3,1,4,23, 1, 4, 2], [11] and [2,12,1] are permutations, but [1,2,11,2,1], [0,10,1] and [1,3,41,3,4] — are not.

Polycarp lost his favorite permutation and found only some of its elements — the numbers b1,b2,bmb_1, b_2, \dots b_m. He is sure that the sum of the lost elements equals ss.

Determine whether one or more numbers can be appended to the given sequence b1,b2,bmb_1, b_2, \dots b_m such that the sum of the added numbers equals ss, and the resulting new array is a permutation?

一个包含 nn 个数的序列被称为排列,当且仅当它恰好包含从 11nn 的所有整数各一次。例如,序列 [3,1,4,23, 1, 4, 2]、[11] 和 [2,12,1] 是排列,但 [1,2,11,2,1]、[0,10,1] 和 [1,3,41,3,4] 不是。

Polycarp 丢失了他最喜爱的排列,仅找到了其中的部分元素——即数字 b1,b2,,bmb_1, b_2, \dots, b_m。他确信所有丢失元素之和等于 ss

请判断:能否向给定序列 b1,b2,,bmb_1, b_2, \dots, b_m 中添加一个或多个数,使得所添加数字之和恰好为 ss,且最终得到的新数组是一个排列?

输入格式

The first line of input contains a single integer tt (1t1001 \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 mm and ss (1m501 \le m \le 50, 1s10001 \le s \le 1000)—-the number of found elements and the sum of forgotten numbers.

The second line of each test set contains mm different integers b1,b2bmb_1, b_2 \dots b_m (1bi501 \le b_i \le 50) — the elements Polycarp managed to find.

输入的第一行包含一个整数 tt1t1001 \le t \le 100),表示测试用例的数量。

接下来是各测试用例的描述。

每个测试用例的第一行包含两个整数 mmss1m501 \le m \le 501s10001 \le s \le 1000),分别表示已找到的元素个数以及被遗忘数字的总和。

每个测试用例的第二行包含 mm 个互不相同的整数 b1,b2,,bmb_1, b_2, \dots, b_m1bi501 \le b_i \le 50),即 Polycarp 成功找到的元素。

输出格式

Print tt 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 bb, that their sum equals ss 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).

输出 tt 行,每行对应一个测试用例的答案。如果可以通过在数组 bb 末尾添加若干个元素(使得这些新增元素的和恰好等于 ss),从而使最终得到的数组是一个排列,则输出 YES;否则输出 NO。

你可以以任意大小写形式输出答案(例如,yEs、yes、Yes 和 YES 均会被判为正确答案)。

输入输出样例

  • 输入#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]m=3, s=13, b=[3,1,4]. You can append to bb the numbers 6,2,56,2,5, the sum of which is 6+2+5=136+2+5=13. Note that the final array will become [3,1,4,6,2,5][3,1,4,6,2,5], which is a permutation.

In the second test case of the example, m=1,s=1,b=[1]m=1, s=1, b=[1]. You cannot append one or more numbers to [1][1] such that their sum equals 11 and the result is a permutation.

In the third test case of the example, m=3,s=3,b=[1,4,2]m=3, s=3, b=[1,4,2]. You can append the number 33 to bb. Note that the resulting array will be [1,4,2,3][1,4,2,3], which is a permutation.

在示例的第一个测试用例中,m=3,s=13,b=[3,1,4]m=3, s=13, b=[3,1,4]。你可以向 bb 末尾添加数字 6,2,56,2,5,其和为 6+2+5=136+2+5=13。注意,最终数组将变为 [3,1,4,6,2,5][3,1,4,6,2,5],这是一个排列。

在示例的第二个测试用例中,m=1,s=1,b=[1]m=1, s=1, b=[1]。你无法向 [1][1] 末尾添加一个或多个数字,使得它们的和等于 11,且结果构成一个排列。

在示例的第三个测试用例中,m=3,s=3,b=[1,4,2]m=3, s=3, b=[1,4,2]。你可以向 bb 末尾添加数字 33。注意,得到的数组为 [1,4,2,3][1,4,2,3],这是一个排列。

输入解题思路,AI测评打分。不知道怎么写?

首页