package codejam;

import fixjava.Pair;

public class Utils {

	public static long minLong(long firstVal, long... otherVals) {
		long minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static int minInt(int firstVal, int... otherVals) {
		int minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static float minFloat(float firstVal, float... otherVals) {
		float minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	/**
	 * ArgMin returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMin(int[] arr) {
		int min = arr[0];
		int argMin = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] < min) {
				min = arr[i];
				argMin = i;
			}
		}
		return new Pair<Integer, Integer>(argMin, min);
	}

	/**
	 * ArgMax returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMax(int[] arr) {
		int max = arr[0];
		int argMax = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] > max) {
				max = arr[i];
				argMax = i;
			}
		}
		return new Pair<Integer, Integer>(argMax, max);
	}

}

package codejam;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.google.common.base.Splitter;

public class ProblemB extends CodeJamRunner {

	
	private int nrOfCases;
	private int testCaseIndex;
	int numberOfGooglers;
	int surprisingTriplets;
	int personalBestBar;
	int maxAbovePersonalBestBar;

	private List<Integer> totalPoints = new ArrayList<Integer>();

	public void process(int lineNr, String line) {
		if (lineNr == 1) {
			nrOfCases = Integer.valueOf(line);
			resetForNextCase();
		} else {
			Iterator<String> split = Splitter.on(" ").split(line).iterator();
			numberOfGooglers = Integer.parseInt(split.next());
			surprisingTriplets = Integer.parseInt(split.next());
			personalBestBar = Integer.parseInt(split.next());
			while ( split.hasNext() ) {
				totalPoints.add(Integer.parseInt(split.next()));
			}
			calc();
			write();
			resetForNextCase();
		}
	}

	private void write() {
		String resultLine = "Case #" + testCaseIndex + ": " + maxAbovePersonalBestBar;
		printlnOutput(resultLine);
	}

	private void calc() {
		int normalAboveCount = 0;
		int surpriseAboveCount = 0;
		for ( int i : totalPoints ) {
			Triplet t = new Triplet( i );
			if ( t.calcMaxNormal() >= personalBestBar ){
				normalAboveCount++;
			}
			else if ( t.calcMaxSurprise() >= personalBestBar ){
				surpriseAboveCount++;
			}
		}
		int surprisesHappened = Math.min(surpriseAboveCount, surprisingTriplets );
		maxAbovePersonalBestBar = normalAboveCount + surprisesHappened;
	}

	private void resetForNextCase() {
		testCaseIndex++;
		totalPoints.clear();
	}

	public static void main(String args[]) {
		ProblemB ao = new ProblemB();
		ao.run(args);
	}

}
