Advertisement
Kali_prasad

pair with difference k v4

Apr 4th, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #pragma GCC optimize ("O3")
  2. #pragma GCC target ("sse4")
  3.  
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8. typedef pair<int, int> pii;
  9. typedef pair<string,int> psi;
  10. typedef map<int,int> mii;
  11. typedef map<long long,long long> mll;
  12. typedef map<string,int> msi;
  13. typedef map<char,int> mci;
  14. typedef vector<int> vi;
  15. typedef vector<string> vs;
  16. typedef vector<char> vc;
  17. typedef vector<ll> vll;
  18. typedef vector<vector<int>> vvi;
  19. typedef vector<vector<string>> vvs;
  20. typedef vector<vector<ll>> vvll;
  21.  
  22. #define FOR(i, a, b) for (auto i=a; i<=(b); i++)
  23. #define FORd(i,b,a) for (int i =b; i >= a; i--)
  24. #define sz(x) (int)(x).size()
  25. #define mp make_pair
  26. #define pb push_back
  27. #define f first
  28. #define s second
  29. #define ins insert
  30.  
  31. const int MOD = 1000000007;
  32. //type functions here
  33. //using map
  34. bool check(mll &m,vi &v,int k,int offset)
  35. {
  36.     int size=(v.size()-2);  
  37.     FOR(i,0,size)
  38.     {
  39.         ll temp=(v[i]+k);
  40.         m[v[i]+offset]--;
  41.         //cout<<" "<<temp<<" "<<v[i]<<" "<<endl;
  42.         if(m[temp+offset]>0) return true;
  43.     }
  44.     return false;
  45. }
  46.  
  47. int main() {
  48.     int tc;
  49.     cin>>tc;
  50.     FOR(j,1,tc){
  51.     vi v;
  52.     int k=11,n=10;
  53.     cin>>n>>k;
  54.     FOR(i,1,n)
  55.     {
  56.         int temp;
  57.         cin>>temp;
  58.         v.pb(temp);
  59.     }
  60.     mll m;
  61.     ll min=*min_element(v.begin(),v.end());
  62.     sort(v.begin(),v.end());
  63.     ll offset=0;
  64.     if(min<0)
  65.     offset=abs(min);
  66.    
  67.    
  68.     for(auto x:v)
  69.     m[x+offset]++;
  70.    
  71.     bool c=check(m,v,k,offset);
  72.     if(c) cout<<"true"<<endl;
  73.     else cout<<"false"<<endl;
  74.    
  75.     }
  76.     return 0;
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement