Please read FAQ for more information.
Something to note:
1. You must name your main class Solution (with exactly that capitalization).
It must contain a public main method. Furthermore, your code must not contain
any package definitions. (Note: Package declarations are allowed in Kotlin.)
2. You need to print your answer in given format, i.e. Case #x: ans
where x is the case number starting from 1 and ans is the answer that test case.
I slightly changed your code to address the issues above.
```Java
import java.util.*;
import java.io.*;
class Solution {
public static int minSum(ArrayList<Integer> list) {
int len = list.size();
int sum = 0;
Collections.sort(list);
Collections.reverse(list);
//System.out.println(list);
for (int i = 1; i < len; i++) {
sum += list.get(0) - list.get(i);
}
return sum;
}
public static void main(String[] args) throws IOException {
BufferedReader ip = new BufferedReader(new
InputStreamReader(System.in));
int t = Integer.parseInt(ip.readLine());
for (int cas = 1; cas <= t; cas++) {
String[] firstLine = ip.readLine().trim().split(" ");
String[] secondLine = ip.readLine().trim().split(" ");
int N = Integer.parseInt(firstLine[0]);
int P = Integer.parseInt(firstLine[1]);
ArrayList<Integer> skillList = new ArrayList<Integer>();
for (int i = 0; i < N; i++) {
skillList.add(Integer.parseInt(secondLine[i]));
}
Collections.sort(skillList);
int min = Integer.MAX_VALUE;
for (int i = 0; i <= N - P; i++) {
ArrayList<Integer> temp = new ArrayList<Integer>();
for (int j = 0; j < P; j++) {
temp.add(skillList.get(i + j));
}
if (min > minSum(temp)) {
min = minSum(temp);
}
}
System.out.printf("Case #%d: %d%n", cas, min);
}
}
}
```
Your solution gave correct result for test set 1 (the visible test) but it is
not good enough to pass the test set 2 (the hidden test) as it is too slow to
meet the running time restriction.
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/f4361956-744f-4e41-85f2-7aaac43f8ed4%40googlegroups.com.