fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4.  
  5. int main() {
  6. ll n;
  7. cin>>n;
  8. ll k;cin>>k;
  9. ll b[n];
  10. for(ll i=0;i<n;i++){
  11. cin>>b[i];
  12. }ll count = 0 ;
  13.  
  14.  
  15.  
  16. for(ll i=0;i<n;i++){
  17.  
  18. for(ll j=i;j<n;j++){
  19. ll d = abs(b[j] - b[i]);
  20. if(d<=k){
  21. count++;
  22. }
  23. }
  24. }
  25. cout<<(count-n);
  26. return 0;
  27. }//RRRRR
Success #stdin #stdout 0.01s 5280KB
stdin
3 1 
2 3 1 
stdout
2