1774B. Coloring

原题链接

B. Coloring

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Cirno_9baka has a paper tape with nn cells in a row on it. As he thinks that the blank paper tape is too dull, he wants to paint these cells with mm kinds of colors. For some aesthetic reasons, he thinks that the ii-th color must be used exactly aiai times, and for every kk consecutive cells, their colors have to be distinct.

Help Cirno_9baka to figure out if there is such a way to paint the cells.

Input

The first line contains a single integer tt (1≤t≤100001≤t≤10000)  — the number of test cases. The description of test cases follows.

The first line of each test case contains three integers nn, mm, kk (1≤k≤n≤1091≤k≤n≤109, 1≤m≤1051≤m≤105, m≤nm≤n). Here nn denotes the number of cells, mm denotes the number of colors, and kk means that for every kk consecutive cells, their colors have to be distinct.

The second line of each test case contains mm integers a1,a2,⋯,ama1,a2,⋯,am (1≤ai≤n1≤ai≤n)  — the numbers of times that colors have to be used. It's guaranteed that a1+a2+…+am=na1+a2+…+am=n.

It is guaranteed that the sum of mm over all test cases does not exceed 105105.

Output

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

Example

input

Copy

 

2

12 6 2

1 1 1 1 1 7

12 6 2

2 2 2 2 2 2

output

Copy

NO
YES

Note

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)(1,2,1,2,3,4,3,4,5,6,5,6). For any 22 consecutive cells, their colors are distinct.

题意就是给你n个单元,有m种颜色,同时涂色时不能出现相同的颜色k次。

思路就是把这n个单元分成n/k个块,对单个块进行分析就能拓展到全局,也就是说当有颜色的数量大于了n/k,就要进行分析,如果正好等于n/k+1,那么就可以把多出的颜色放在新的块中,放在多出的n%k中,如果多出的颜色数量大于n%k那就无法满足要求。

ACcode:

mp是存储相同颜色数量的数量。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int manx = 2e5 + 10;

int a[manx];
void solve()
{
	int n, m, k;
	cin >> n >> m >> k;
	int maxn = 0;
	map<int, int>mp;
	for (int i = 0; i < m; i++)
	{
		cin >> a[i];
		maxn = max(maxn, a[i]);
		mp[a[i]]++;
	}
	if (maxn <= n / k)
	{
		cout << "YES" << endl;
	}
	else if (maxn == n / k + 1 && mp[maxn] <= n % k)
	{
		cout << "YES" << endl;
	}
	else
		cout << "NO" << endl;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值