Advertisement
Josif_tepe

Untitled

Mar 9th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include<algorithm>
  3. #include <fstream>
  4. #include <map>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. //    ifstream cin("out.txt");
  10.     long long n,k;
  11.     cin>>n>>k;
  12.     long long a[n];
  13.     map<long long, long long> m;
  14.     for(int i=0;i<n;i++)
  15.     {
  16.         cin>>a[i];
  17.         m[a[i]]++;
  18.     }
  19.     sort(a,a+n);
  20.     long long s=0;
  21. //    for(int i  =0; i < n; i++) {
  22. //        cout << a[i] << " " ;
  23. //    }
  24. //    cout << endl;
  25.     for(int i=0;i<n;i++)
  26.     {
  27.         s += m[a[i] - k];
  28.        
  29.     }
  30.     if(k == 0) {
  31.         s -= n;
  32.         s /= 2;
  33.     }
  34.     cout<<s;
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement