Algorithm


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 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 ai�� 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.

Input

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

The first line of each test case contains three integers nmk (1kn1091≤�≤�≤1091m1051≤�≤105mn�≤�). 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 a1,a2,,am�1,�2,⋯,�� (1ain1≤��≤�)  — the numbers of times that colors have to be used. It's guaranteed that a1+a2++am=n�1+�2+…+��=�.

It is guaranteed that the sum of m 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.

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include<bits/stdc++.h>
using namespace std;


#define ll long long
#define endl "\n"
#define debug(n) cout<<(n)<<endl;
#define pb push_back
const ll INF = 2e18 + 99;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t;
  cin>>t;
  while(t--){
    int n, m, k;
    cin>>n>>m>>k;
    int seg;
    if (n % k != 0){
      seg = n/k + 1;
    }
    else{
      seg = n /k;
    }
    int x, count = 0;
    bool check = true;
    for(int i = 0; i < m; i++){
      cin>>x;
      if(x > seg){
        check = false;
      }
      if(x == seg){
        count++;
      }
    }
    if(n % k != 0 && count > n % k){
      check = false;
    }
    if(check){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2
12 6 2
1 1 1 1 1 7
12 6 2
2 2 2 2 2 2

Output

x
+
cmd
NO
YES
Advertisements

Demonstration


Codeforcess Solution 1774-B B. Coloring ,C++, Java, Js and Python,1774-B,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+