ZCO-2014::Variation

 

#include <bits/stdc++.h>
using namespace std ;
#define boost ios::sync_with_stdio(false);cin.tie(0)

int main (){
int n ,k ;
cin >> n >> k ;
int arr[n];
for (int i = 0; i < n; ++i) {
cin >> arr[i];

}
int count{0};
int i = 0 ;
int j = 0 ;
sort(arr,arr + n);
while (j < n){
if (arr[j] - arr[i] >= k){
count += n-j;
i++ ;
} else{
j++;
}
}
cout << count << '\n';

return 0;
}

Comments

Popular posts from this blog

CodeChef::CSUB

How Recursion Works?

CodeChef::TREE2