Algorithm


A. Replacing Elements
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You have an array a1,a2,,an�1,�2,…,��. All ai�� are positive integers.

In one step you can choose three distinct indices ij, and k (ij�≠�ik�≠�jk�≠�) and assign the sum of aj�� and ak�� to ai��, i. e. make ai=aj+ak��=��+��.

Can you make all ai�� lower or equal to d using the operation above any number of times (possibly, zero)?

Input

The first line contains a single integer t (1t20001≤�≤2000) — the number of test cases.

The first line of each test case contains two integers n and d (3n1003≤�≤1001d1001≤�≤100) — the number of elements in the array a and the value d.

The second line contains n integers a1,a2,,an�1,�2,…,�� (1ai1001≤��≤100) — the array a.

Output

For each test case, print YES, if it's possible to make all elements ai�� less or equal than d using the operation above. Otherwise, print NO.

You may print each letter in any case (for example, YESYesyesyEs will all be recognized as positive answer).

Example
input
Copy
3
5 3
2 3 2 5 4
3 4
2 4 4
5 4
2 1 5 3 6
output
Copy
NO
YES
YES
Note

In the first test case, we can prove that we can't make all ai3��≤3.

In the second test case, all ai�� are already less or equal than d=4�=4.

In the third test case, we can, for example, choose i=5�=5j=1�=1k=2�=2 and make a5=a1+a2=2+1=3�5=�1+�2=2+1=3. Array a will become [2,1,5,3,3][2,1,5,3,3].

After that we can make a3=a5+a2=3+1=4�3=�5+�2=3+1=4. Array will become [2,1,4,3,3][2,1,4,3,3] and all elements are less or equal than d=4�=4.

 



 

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;
const ll INF = 2e18 + 99;

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

  int t;
  cin>>t;
  while(t--){
    int n, d;
    cin>>n>>d;
    int arr[n];
    for(int i = 0; i < n; i++){
      cin>>arr[i];
    }
    sort(arr, arr+n);
    if(arr[n-1] <= d){
      cout<<"YES"<<endl;
    }
    else if(arr[0] + arr[1] <= d){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
5 3
2 3 2 5 4
3 4
2 4 4
5 4
2 1 5 3 6

Output

x
+
cmd
NO
YES
YES
Advertisements

Demonstration


Codeforcess Solution 1473-A A. Replacing Elements ,C++, Java, Js and Python,1473-A,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+