Skip to content

Instantly share code, notes, and snippets.

@bchetty
Created May 23, 2013 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bchetty/5638772 to your computer and use it in GitHub Desktop.
Save bchetty/5638772 to your computer and use it in GitHub Desktop.
GCJ 2012 - Dancing With Googlers
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
/**
*
* @author Babji Prashanth, Chetty
*/
public class DancingGooglers {
public int findMaxGooglers(int N, int s, int p, ArrayList<Integer> scoreList) {
int res = 0;
int surpriseNum = s;
int threshold = p + (2 * (p - 2));
Collections.sort(scoreList);
for(Integer score: scoreList) {
if(score >= p) {
System.out.print("Score : " + score + " divided into : ");
int[] triplet = split(score);
if(triplet[2] >= p) {
res++;
} else if(surpriseNum > 0 && score >= threshold) {
res++;
surpriseNum--;
}
}
}
return res;
}
private int[] split(int score) {
int div = score/3;
int rem = score - (3 * div);
int[] triplet = new int[3];
triplet[0] = div;
triplet[1] = div;
triplet[2] = div;
//System.out.println("Div : " + div + " Init Rem : " + rem);
int index = 0;
while(rem > 0) {
if(index > 2) {
index = 0;
}
triplet[index] += 1;
index++;
rem--;
}
Arrays.sort(triplet);
System.out.println(triplet[0] + " - " + triplet[1] + " - " + triplet[2]);
return triplet;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment