Hi all, I am new to solving problems on codingcompetitions.withgoogle, I am stuck at some point, please help me find where I am going wrong
Question - https://codingcompetitions.withgoogle.com/kickstart/round/0000000000050e01/00000000000698d6 Solution ( What I wrote): import java.util.*; import java.io.*; class KickStart{ 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()); while(t-- >0){ 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.println(min); } } } -- 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/c0897448-984c-488b-9870-5dfc67ef38f9%40googlegroups.com.
