CF1668B.Social Distance
入门
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
m chairs are arranged in a circle sequentially. The chairs are numbered from 0 to m−1. n people want to sit in these chairs. The i-th of them wants at least a[i] empty chairs both on his right and left side.
More formally, if the i-th person sits in the j-th chair, then no one else should sit in the following chairs: (j−a[i])modm, (j−a[i]+1)modm, ... (j+a[i]−1)modm, (j+a[i])modm.
Decide if it is possible to sit down for all of them, under the given limitations.
m 把椅子按顺序围成一个圆圈排列。椅子编号从 0 到 m−1。有 n 个人希望坐在这些椅子上。其中第 i 个人要求其左右两侧各自至少有 a[i] 个空椅子。
更严格地讲,若第 i 个人坐在第 j 把椅子上,则以下椅子上均不得坐其他人:
(j−a[i])modm, (j−a[i]+1)modm, …, (j+a[i]−1)modm, (j+a[i])modm。
请判断在给定限制下,是否能让所有 n 个人都坐下。
输入格式
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤5⋅104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n and m (2≤n≤105, 1≤m≤109) — the number of people and the number of chairs.
The next line contains n integers, a1, a2, ... an (1≤ai≤109) — the minimum number of empty chairs, on both sides of the i-th person.
It is guaranteed that the sum of n over all test cases will not exceed 105.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤5⋅104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(2≤n≤105,1≤m≤109),分别表示人数和椅子总数。
下一行包含 n 个整数 a1,a2,…,an(1≤ai≤109),其中 ai 表示第 i 个人两侧所需的最少空椅子数。
保证所有测试用例中 n 的总和不超过 105。
输出格式
For each test case print "YES" (without quotes) if it is possible for everyone to sit down and fulfil the restrictions, and "NO" (without quotes) otherwise.
You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" will all be recognized as positive answers).
对于每个测试用例,如果所有人都能坐下并满足所有限制条件,则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。
你可以以任意大小写形式输出每个字母(例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答)。
输入输出样例
输入#1
6 3 2 1 1 1 2 4 1 1 2 5 2 1 3 8 1 2 1 4 12 1 2 1 3 4 19 1 2 1 3
输出#1
NO YES NO YES NO YES
说明/提示
Test case 1: n>m, so they can not sit down.
Test case 2: the first person can sit 2-nd and the second person can sit in the 0-th chair. Both of them want at least 1 empty chair on both sides, chairs 1 and 3 are free, so this is a good solution.
Test case 3: if the second person sits down somewhere, he needs 2 empty chairs, both on his right and on his left side, so it is impossible to find a place for the first person, because there are only 5 chairs.
Test case 4: they can sit in the 1-st, 4-th, 7-th chairs respectively.
测试用例 1:n>m,因此他们无法就座。
测试用例 2:第一个人可以坐在第 2 个座位上,第二个人可以坐在第 0 个座位上。两人都要求在自己左右两侧至少各有 1 个空座位,而座位 1 和 3 恰好为空,因此这是一个可行的方案。
测试用例 3:如果第二个人就座,则他左右两侧均需各有 2 个空座位,因此无法为第一个人找到合适的位置,因为总共只有 5 个座位。
测试用例 4:他们可以分别坐在第 1、第 4、第 7 个座位上。
输入解题思路,AI测评打分。不知道怎么写?