Problem link - http://www.codechef.com/problems/TLG
Solution-
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.SortedSet;
import java.util.TreeSet;
public class TheLeadGame {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(System.out)));
int num = Integer.parseInt(br.readLine());
SortedSet<Integer> pl1 = new TreeSet<Integer>();
SortedSet<Integer> pl2 = new TreeSet<Integer>();
while (num-- > 0) {
String strr[] = br.readLine().split(" ");
if (Integer.parseInt(strr[0]) > Integer.parseInt(strr[1])) {
pl1.add((Integer.parseInt(strr[0])) - Integer.parseInt(strr[1]));
} else {
pl2.add((Integer.parseInt(strr[1])) - Integer.parseInt(strr[0]));
}
}
if (pl1.last() > pl2.last()) {
pw.println(1 + " " + pl1.last());
} else {
pw.println(2 + " " + pl2.last());
}
pw.close();
}
}