http://codeforces.com/contest/32
A
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define maxn 1000005 8 typedef long long ll; 9 typedef unsigned long long ull; 10 /*#ifndef ONLINE_JUDGE 11 freopen("1.txt","r",stdin); 12 #endif */ 13 14 int n,m; 15 int a[1005]; 16 17 int main(){ 18 #ifndef ONLINE_JUDGE 19 // freopen("1.txt","r",stdin); 20 #endif 21 std::ios::sync_with_stdio(false); 22 cin>>n>>m; 23 int ans=0; 24 for(int i=1;i<=n;i++) cin>>a[i]; 25 for(int i=1;i<=n;i++){ 26 for(int j=1;j<=n;j++){ 27 if(i!=j&&abs(a[i]-a[j])<=m){ 28 ans++; 29 } 30 } 31 } 32 cout<<ans<<endl; 33 }