Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize ("O3")
- #pragma GCC target ("sse4")
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef pair<string,int> psi;
- typedef vector<int> vi;
- typedef vector<string> vs;
- typedef vector<ll> vll;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<string>> vvs;
- typedef vector<vector<ll>> vvll;
- #define FOR(i, a, b) for (auto i=a; i<=(b); i++)
- #define FORd(i,b,a) for (int i =b; i >= a; i--)
- #define sz(x) (int)(x).size()
- #define mp make_pair
- #define pb push_back
- #define f first
- #define s second
- #define ins insert
- const int MOD = 1000000007;
- //type functions here
- int main() {
- int tc;
- cin>>tc;
- FOR(i,1,tc)
- {
- int size,k;
- cin>>size>>k;
- vi v;
- FOR(j,1,size)
- {
- //cout<<"z";
- int temp;
- cin>>temp;
- v.pb(temp);
- }
- int left=size-2,right=size-1;
- string s="false";
- sort(v.begin(),v.end());
- k=abs(k);
- while(right>left&&left>=0)
- {
- //cout<<"k";
- int diff=v[right]-v[left];
- diff=abs(diff);
- //cout<<diff<<" ";
- if(diff<k)
- left--;
- else if(diff>k)
- right--;
- else
- {
- s="true";
- break;
- }
- }
- cout<<s<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment