Algorithm
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
3
5 3
2 3 2 5 4
3 4
2 4 4
5 4
2 1 5 3 6
5 3
2 3 2 5 4
3 4
2 4 4
5 4
2 1 5 3 6
Output
NO
YES
YES
YES
YES
Demonstration
Codeforcess Solution 1473-A A. Replacing Elements ,C++, Java, Js and Python,1473-A,Codeforcess Solution