Problem Link : http://www.codechef.com/problems/CLEANUP
Solution :
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 CleaningUp {
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) {
String str = br.readLine();
int totjobs = Integer.parseInt(str.split(" ")[0]);
int arr[] = new int[totjobs + 1];
int compjobs = Integer.parseInt(str.split(" ")[1]);
str = br.readLine();
String split[] = str.split(" ");
if (compjobs > 0) {
for (String x : split) {
arr[Integer.parseInt(x)] = 1;
}
}
ArrayList<Integer> first = new ArrayList<Integer>();
ArrayList<Integer> second = new ArrayList<Integer>();
int count = 0;
for (int i = 1; i < arr.length; i++) {
if (arr[i] == 1) {
continue;
}
if (count % 2 == 0) {
first.add(i);
} else {
second.add(i);
}
count++;
}
for (Integer i : first) {
System.out.print(i + " ");
}
System.out.println("");
for (Integer i : second) {
System.out.print(i + " ");
}
System.out.println("");
}
}
}
No comments:
Post a Comment