Josif_tepe

Untitled

Oct 22nd, 2025
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <map>
  5. using namespace std;
  6. typedef long long ll;
  7.  
  8.  
  9. int main() {
  10.     int n, K;
  11.     cin >> n >> K;
  12.    
  13.     vector<int> v(n);
  14.     map<int, int> cnt;
  15.    
  16.     for(int i = 0; i < n; i++) {
  17.         cin >> v[i];
  18.        
  19.         cnt[v[i]]++;
  20.     }
  21.    
  22.     ll res = 0;
  23.     for(int i = 0; i < n; i++) {
  24.         res += cnt[v[i] + K];
  25.     }
  26.    
  27.     if(K == 0) {
  28.         res -= n;
  29.         res /= 2;
  30.     }
  31.     cout << res << endl;
  32.  
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment