Problem Link : http://www.codechef.com/problems/COOLING
Solution :
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
/**
*
* @author XCoder
*/
class CoolingPies {
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static PrintWriter pw = new PrintWriter(System.out);
public static int readIntLine() throws IOException {
return Integer.parseInt(br.readLine());
}
public static long readLongLine() throws IOException {
return Long.parseLong(br.readLine());
}
public static void main(String[] args) throws IOException {
int test = readIntLine();
while (test-- > 0) {
int totalpiles = readIntLine();
ArrayList<Integer> wtPies = new ArrayList<Integer>();
ArrayList<Integer> wtLimitsRacks = new ArrayList<Integer>();
String str1 = br.readLine();
String str2 = br.readLine();
for (String x : str1.split(" ")) {
wtPies.add(Integer.valueOf(x));
}
for (String x : str2.split(" ")) {
wtLimitsRacks.add(Integer.valueOf(x));
}
Collections.sort(wtPies);
Collections.sort(wtLimitsRacks);
int count = 0;
int pieindex = wtPies.size() - 1;
int rackindex = pieindex;
// for (int i = wtPies.size() - 1; i >= 0; i--) {
// int x=wtPies.get(i);
while (pieindex >= 0) {
if (wtPies.get(pieindex).intValue() <= wtLimitsRacks.get(rackindex).intValue()) {
count++;
rackindex--;
}
pieindex--;
}
// pw.println(totalpiles - wtPies.size());
pw.println(count);
}
pw.flush();
pw.close();
}
}
No comments:
Post a Comment