Skip to content

Instantly share code, notes, and snippets.

@panreel
Last active January 11, 2017 02:08
Show Gist options
  • Save panreel/6c809c781d76e19b0e4b98c050674e9c to your computer and use it in GitHub Desktop.
Save panreel/6c809c781d76e19b0e4b98c050674e9c to your computer and use it in GitHub Desktop.
Facebook HackerCup 2017 - Qualifications R2
import java.io.*;
import java.util.*;
public class HackerCupQualR2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int times = in.nextInt();
for(int i = 1; i <= times; i++) {
int l = in.nextInt();
int[] ws = new int[l];
for(int j = 0; j < l; j++)
ws[j] = in.nextInt();
Arrays.sort(ws);
System.out.println("Case #" + i + ": " + trips(ws));
}
}
public static int trips(int[] ws) {
int count = 0, back = ws.length - 1, front = 0;
while(front < back) {
int b = ws[back]; back--;
if(b < 50) front += (50 / b);
count++;
}
return count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment