Problem Link : http://www.codechef.com/problems/TLG
Solution :
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
/**
*
* @author XCoder
*/
class TheLeadGame {
public static int readIntLine() throws IOException {
return Integer.parseInt(br.readLine());
}
public static long readLongLine() throws IOException {
return Long.parseLong(br.readLine());
}
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int rounds = readIntLine();
int winner = 0;
int lead = 0;
int finallead = -1;
int score1 = 0;
int score2 = 0;
while (rounds-- > 0) {
String str = br.readLine();
String split[] = str.split(" ");
int initp1score = Integer.parseInt(split[0]);
int initp2score = Integer.parseInt(split[1]);
score1 += initp1score;
score2 += initp2score;
if (score1 > score2) {
lead = score1 - score2;
if (lead > finallead) {
winner = 1;
finallead = lead;
}
} else {
lead = score2 - score1;
if (lead > finallead) {
winner = 2;
finallead = lead;
}
}
// System.out.println("p1 : "+score1+" p2: "+score2+" winner "+winner+" finallead "+finallead );
}
pw.println(winner + " " + finallead);
pw.flush();
pw.close();
}
}
No comments:
Post a Comment