-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_1.java
More file actions
53 lines (46 loc) · 1.67 KB
/
Copy pathTest_1.java
File metadata and controls
53 lines (46 loc) · 1.67 KB
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
package test;
import java.io.*;
import java.util.*;
public class Test_1 {
public static void main(String[] args) throws IOException{
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(buffer.readLine());
int t = 0;
while(t <T){
String[] input = buffer.readLine().split(" ");
int n = Integer.parseInt(input[0]);
int k = Integer.parseInt(input[1]);
ArrayList<int []>[] arr = new ArrayList[n*n];
int[] put = new int[n];
input = buffer.readLine().split(" ");
for(int i = 0; i < n*n; i++){
arr[i] = new ArrayList<>();
}
for(int i = 0; i< n; i++){
put[i] = Integer.parseInt(input[i]);
}
Arrays.sort(put);
int index=0;
for(int i = 0; i <n ;i++){
for(int j = 0; j<n; j++){
int value = put[i];
int value2= put[j];
arr[index++].add(new int[]{value, value2});
}
}
Arrays.sort(arr, new Comparator<ArrayList<int[]>>() {
@Override
public int compare(ArrayList<int[]> o1, ArrayList<int[]> o2) {
if(o1.get(0)[0] == o2.get(0)[0]){
return o1.get(0)[1] - o2.get(0)[1];
}
return o1.get(0)[0] - o2.get(0)[0];
}
});
int a = arr[k-1].get(0)[0];
int b = arr[k-1].get(0)[1];
System.out.println("#" + (t+1) + " " +(a+b));
t++;
}
}
}