fork download
  1. /*
  2.   Cred : SunnyYeahBoi
  3.   It's my last chance (⌐■_■)
  4.   Problem :
  5. */
  6.  
  7. #include<bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. #define int long long
  12. #define double long double
  13. #define endl "\n"
  14. #define NAME "a"
  15.  
  16. const int MAXN = 1e6 + 5;
  17. const int inf = 1e18;
  18. const int MOD = 1e9 + 7;
  19.  
  20. void FileInput(){
  21. if(fopen(NAME".inp" , "r") == NULL)
  22. freopen(NAME".inp" , "w" , stdout);
  23. freopen(NAME".inp" , "r" , stdin);
  24. freopen(NAME".out" , "w" , stdout);
  25. }
  26.  
  27. int n , k;
  28. int a[MAXN];
  29. map<int , int> mp;
  30.  
  31. void solve(){
  32. cin >> n >> k;
  33. for(int i = 1 ; i <= n ; i++){
  34. cin >> a[i];
  35. mp[a[i]]++;
  36. }
  37.  
  38. int res = 0;
  39. for(auto x : mp){
  40. int X = x.second;
  41. int Y = mp[x.first - k];
  42. res += X * Y;
  43. }
  44. cout << res << endl;
  45. }
  46.  
  47. int32_t main(){
  48. FileInput();
  49. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  50. int t = 1;
  51. // cin >> t;
  52. while(t--)
  53. solve();
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Standard output is empty