// APPROX2, Setter's solution #include #include #include using namespace std; #define maxn 100000 + 5 int n, m, k, i, j, a[maxn], opt, ans, tn; int main (int argc, char * const argv[]) { scanf("%d", &tn); for(; tn; tn--) { scanf("%d %d", &n, &k); for(i = 1; i <= n; i++) scanf("%d", &a[i]); // reading input opt = 2000000000; ans = 0; for(i = 1; i <= n; i++) for(j = i + 1; j <= n; j++) if (abs(a[i] + a[j] - k) < opt) { // finding the closest pair opt = abs(a[i] + a[j] - k); ans = 1; } else if (abs(a[i] + a[j] - k) == opt) ++ans; // counting the number of the closest pairs printf("%d %d\n", opt, ans); } return 0; }