A15613 | Coloring
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Cirno\_9baka has a paper tape with $n$ cells in a row on it. As he thinks that the blank paper tape is too dull, he wants to paint these cells with $m$ kinds of colors. For some aesthetic reasons, he thinks that the $i$ -th color must be used exactly $a_i$ times, and for every $k$ consecutive cells, their colors have to be distinct.
Help Cirno\_9baka to figure out if there is such a way to paint the cells.
Help Cirno\_9baka to figure out if there is such a way to paint the cells.
输入格式
The first line contains a single integer $t$ ( $1 \leq t \leq 10\,000$ ) — the number of test cases. The description of test cases follows.
The first line of each test case contains three integers $n$ , $m$ , $k$ ( $1 \leq k \leq n \leq 10^9$ , $1 \leq m \leq 10^5$ , $m \leq n$ ). Here $n$ denotes the number of cells, $m$ denotes the number of colors, and $k$ means that for every $k$ consecutive cells, their colors have to be distinct.
The second line of each test case contains $m$ integers $a_1, a_2, \cdots , a_m$ ( $1 \leq a_i \leq n$ ) — the numbers of times that colors have to be used. It's guaranteed that $a_1 + a_2 + \ldots + a_m = n$ .
It is guaranteed that the sum of $m$ over all test cases does not exceed $10^5$ .
The first line of each test case contains three integers $n$ , $m$ , $k$ ( $1 \leq k \leq n \leq 10^9$ , $1 \leq m \leq 10^5$ , $m \leq n$ ). Here $n$ denotes the number of cells, $m$ denotes the number of colors, and $k$ means that for every $k$ consecutive cells, their colors have to be distinct.
The second line of each test case contains $m$ integers $a_1, a_2, \cdots , a_m$ ( $1 \leq a_i \leq n$ ) — the numbers of times that colors have to be used. It's guaranteed that $a_1 + a_2 + \ldots + a_m = n$ .
It is guaranteed that the sum of $m$ over all test cases does not exceed $10^5$ .
输出格式
For each test case, output "YES" if there is at least one possible coloring scheme; otherwise, output "NO".
You may print each letter in any case (for example, "YES", "Yes", "yes", and "yEs" will all be recognized as positive answers).
You may print each letter in any case (for example, "YES", "Yes", "yes", and "yEs" will all be recognized as positive answers).
输入输出样例
输入 #1
2 12 6 2 1 1 1 1 1 7 12 6 2 2 2 2 2 2 2
输出 #1
NO YES
In the first test case, there is no way to color the cells satisfying all the conditions.
In the second test case, we can color the cells as follows: $(1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6)$ . For any $2$ consecutive cells, their colors are distinct.
In the second test case, we can color the cells as follows: $(1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6)$ . For any $2$ consecutive cells, their colors are distinct.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted