Codeforces #32 (div2) A "Reconnaissance "

問題:http://codeforces.com/contest/32/problem/A

ラクティス.
背の差が指定された差以内の組み合わせの総数を求める.
1,2と2,1は別とカウント.

import java.util.*;

public class A_Reconnaissance {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt(), d = s.nextInt(), sum = 0;
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = s.nextInt();
			for (int j = 0; j < i; ++j) {
				if (Math.abs(a[i] - a[j]) <= d) {
					sum += 2;
				}
			}
		}
		System.out.println(sum);
	}
}