Guest User

Untitled

a guest
Feb 29th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int mod(int a,int b){
  5.     if (a - b >=0 ){
  6.         return a-b;
  7.     }
  8.     else{
  9.         return b-a;
  10.     }
  11. }
  12. int main(){
  13.     int N,K;
  14.     cin >> N >> K;
  15.     int A[N];
  16.     for (int i = 0; i < N; i++){
  17.         cin >> A[i];
  18.     }
  19.     sort(A,A+N);
  20.     reverse(A,A+N);
  21.     int count;
  22.     for (int i=0; i<N; i++){
  23.         for(int j = i; i<N; i++){
  24.             if(mod(A[i],A[j])>= K){
  25.                 count++;
  26.             }
  27.         }
  28.     }
  29.     cout << count << endl;
  30. }
Add Comment
Please, Sign In to add comment