Skip to content

Commit

Permalink
Create 1656B - Subtract Operation.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
SK-AHMD authored Nov 28, 2022
1 parent 7e73618 commit 84eaa26
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Solutions/1656B - Subtract Operation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// sk
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
int arr[n+2];

for(int i=0;i<n;i++)
cin>>arr[i];

sort(arr,arr+n);
bool flag = false;

for(int i=0,j=0;i<n;i++){
while(j<i && arr[i]-arr[j]>k) j++;
if(arr[i]-arr[j]==k) {flag = true; break;}
}
if(flag ==true) cout<<"YES\n";
else cout<<"NO\n";

}
return 0;

}

0 comments on commit 84eaa26

Please sign in to comment.