-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAPPROX2.java
More file actions
55 lines (35 loc) · 901 Bytes
/
APPROX2.java
File metadata and controls
55 lines (35 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Akash Yadav
// @Hudson Lane, Delhi
// 16th June 18
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
class TestClass{
//https://www.codechef.com/problems/APPROX2
public static Scanner scn = new Scanner(System.in);
public static void main (String[] args) throws java.lang.Exception{
int T = scn.nextInt();
while(T-- > 0){
int N = scn.nextInt();
int K = scn.nextInt();
int[] arr = new int[N];
for(int i = 0; i < N; i++)
arr[i] = scn.nextInt();
long min = 2000000000;
long freq = 0;
for(int i = 0; i < N; i++){
for(int j = i + 1; j < N; j++){
long sum = Math.abs(arr[i] + arr[j] - K);
if(sum < min){
min = sum;
freq = 1;
} else if(sum == min){
freq++;
}
}
}
System.out.println(min + " " + freq);
}
}
}