CF1461D.Divide and Summarize
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Mike received an array a of length n as a birthday present and decided to test how pretty it is.
An array would pass the i-th prettiness test if there is a way to get an array with a sum of elements totaling si, using some number (possibly zero) of slicing operations.

An array slicing operation is conducted in the following way:
- assume mid=⌊2max(array)+min(array)⌋, where max and min — are functions that find the maximum and the minimum array elements. In other words, mid is the sum of the maximum and the minimum element of array divided by 2 rounded down.
- Then the array is split into two parts left and right. The left array contains all elements which are less than or equal mid, and the right array contains all elements which are greater than mid. Elements in left and right keep their relative order from array.
- During the third step we choose which of the left and right arrays we want to keep. The chosen array replaces the current one and the other is permanently discarded.
You need to help Mike find out the results of q prettiness tests.
Note that you test the prettiness of the array a, so you start each prettiness test with the primordial (initial) array a. Thus, the first slice (if required) is always performed on the array a.
迈克收到了一个长度为 n 的数组 a 作为生日礼物,并决定测试它的“美观度”。
若存在一种方式,通过对数组进行若干次(可能为零次)切片操作,得到一个元素和恰好为 si 的数组,则该数组通过第 i 个美观度测试。

一次数组切片操作按如下方式进行:
- 设 mid=⌊2max(array)+min(array)⌋,其中 max 和 min 分别表示求数组中最大值与最小值的函数。换言之,mid 是数组最大值与最小值之和除以 2 后向下取整。
- 然后将原数组划分为两个子数组:left 和 right。left 包含所有小于等于 mid 的元素,right 包含所有大于 mid 的元素;left 和 right 中的元素均保持其在原数组中的相对顺序。
- 第三步中,我们选择保留 left 或 right 中的一个子数组,被选中的子数组将取代当前数组,另一个则被永久丢弃。
你需要帮助迈克判断 q 个美观度测试的结果。
注意:你始终是对原始数组 a 进行美观度测试,因此每次美观度测试都从初始数组 a 开始。也就是说,第一次切片操作(如果需要的话)总是作用于数组 a。
输入格式
Each test contains one or more test cases. The first line contains the number of test cases t (1≤t≤100).
The first line of each test case contains two integers n and q (1≤n,q≤105) — the length of the array a and the total number of prettiness tests.
The second line of each test case contains n integers a1,a2,...,an (1≤ai≤106) — the contents of the array a.
Next q lines of each test case contain a single integer si (1≤si≤109) — the sum of elements which Mike wants to get in the i-th test.
It is guaranteed that the sum of n and the sum of q does not exceed 105 (∑n,∑q≤105).
每个测试包含一个或多个测试用例。第一行包含测试用例的数量 t(1≤t≤100)。
每个测试用例的第一行包含两个整数 n 和 q(1≤n,q≤105)—— 分别表示数组 a 的长度以及总共的“美观度”测试次数。
每个测试用例的第二行包含 n 个整数 a1,a2,...,an(1≤ai≤106)—— 表示数组 a 的内容。
每个测试用例接下来的 q 行,每行包含一个整数 si(1≤si≤109)—— 表示 Mike 在第 i 次测试中希望得到的元素之和。
保证所有测试用例的 n 之和以及所有测试用例的 q 之和均不超过 105(即 ∑n,∑q≤105)。
输出格式
Print q lines, each containing either a "Yes" if the corresponding prettiness test is passed and "No" in the opposite case.
输出 q 行,每行包含一个字符串:若对应的美观性测试通过,则输出 "Yes";否则输出 "No"。
输入输出样例
输入#1
2 5 5 1 2 3 4 5 1 8 9 12 6 5 5 3 1 3 1 3 1 2 3 9 11
输出#1
Yes No Yes No Yes No Yes No Yes Yes
说明/提示
Explanation of the first test case:
-
We can get an array with the sum s1=1 in the following way:
1.1 a=[1,2,3,4,5], mid=21+5=3, left=[1,2,3], right=[4,5]. We choose to keep the left array.
1.2 a=[1,2,3], mid=21+3=2, left=[1,2], right=[3]. We choose to keep the left array.
1.3 a=[1,2], mid=21+2=1, left=[1], right=[2]. We choose to keep the left array with the sum equalling 1.
-
It can be demonstrated that an array with the sum s2=8 is impossible to generate.
-
An array with the sum s3=9 can be generated in the following way:
3.1 a=[1,2,3,4,5], mid=21+5=3, left=[1,2,3], right=[4,5]. We choose to keep the right array with the sum equalling 9.
-
It can be demonstrated that an array with the sum s4=12 is impossible to generate.
-
We can get an array with the sum s5=6 in the following way:
5.1 a=[1,2,3,4,5], mid=21+5=3, left=[1,2,3], right=[4,5]. We choose to keep the left with the sum equalling 6.
Explanation of the second test case:
-
It can be demonstrated that an array with the sum s1=1 is imposssible to generate.
-
We can get an array with the sum s2=2 in the following way:
2.1 a=[3,1,3,1,3], mid=21+3=2, left=[1,1], right=[3,3,3]. We choose to keep the left array with the sum equalling 2.
-
It can be demonstrated that an array with the sum s3=3 is imposssible to generate.
-
We can get an array with the sum s4=9 in the following way:
4.1 a=[3,1,3,1,3], mid=21+3=2, left=[1,1], right=[3,3,3]. We choose to keep the right array with the sum equalling 9.
-
We can get an array with the sum s5=11 with zero slicing operations, because array sum is equal to 11.
第一个测试用例的说明:
-
我们可以通过如下方式得到一个和为 s1=1 的数组:
1.1 a=[1,2,3,4,5],mid=21+5=3,left=[1,2,3],right=[4,5]。我们选择保留 left 数组。
1.2 a=[1,2,3],mid=21+3=2,left=[1,2],right=[3]。我们选择保留 left 数组。
1.3 a=[1,2],mid=21+2=1,left=[1],right=[2]。我们选择保留 left 数组,其和为 1。
-
可以证明,无法生成和为 s2=8 的数组。
-
和为 s3=9 的数组可通过如下方式生成:
3.1 a=[1,2,3,4,5],mid=21+5=3,left=[1,2,3],right=[4,5]。我们选择保留 right 数组,其和为 9。
-
可以证明,无法生成和为 s4=12 的数组。
-
我们可以通过如下方式得到一个和为 s5=6 的数组:
5.1 a=[1,2,3,4,5],mid=21+5=3,left=[1,2,3],right=[4,5]。我们选择保留 left 数组,其和为 6。
第二个测试用例的说明:
-
可以证明,无法生成和为 s1=1 的数组。
-
我们可以通过如下方式得到一个和为 s2=2 的数组:
2.1 a=[3,1,3,1,3],mid=21+3=2,left=[1,1],right=[3,3,3]。我们选择保留 left 数组,其和为 2。
-
可以证明,无法生成和为 s3=3 的数组。
-
我们可以通过如下方式得到一个和为 s4=9 的数组:
4.1 a=[3,1,3,1,3],mid=21+3=2,left=[1,1],right=[3,3,3]。我们选择保留 right 数组,其和为 9。
-
我们可以在不进行任何切分操作的情况下得到一个和为 s5=11 的数组,因为原数组的和即为 11。
输入解题思路,AI测评打分。不知道怎么写?