fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n,k ; cin>>n>>k;
  7. vector<int>arr(n);
  8. for(int i = 0 ; i<n;i++){
  9. cin>>arr[i];
  10. }
  11. int count = 0 ;
  12. for(int i =0;i<n;i++){
  13. for(int j = i +1;j<n;j++){
  14. if(abs(arr[i]-arr[j])==k)count++;
  15. }
  16. }
  17. cout<<count;
  18. // your code goes here
  19. return 0;
  20. }
Success #stdin #stdout 0s 5324KB
stdin
5 2
1 2 3 4 2 
stdout
3