Pages

Friday, December 14, 2007

USACO: Milking Cows

/*
ID: wsoethe1
LANG: JAVA
TASK: milk2
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

class milk2 {
public static void main(String[] args) throws IOException {
BufferedReader filein = new BufferedReader(new FileReader("milk2.in"));
PrintWriter fileOut = new PrintWriter(new BufferedWriter(
new FileWriter("milk2.out")));
int n, x, y, t, ans, min = 1000000, max = 0, i;
int[] h = new int[1000001];
n = Integer.parseInt(filein.readLine());
for (i = 0; i < n; i++) {
String s = filein.readLine();
x = Integer.parseInt(s.split(" ")[0]);
y = Integer.parseInt(s.split(" ")[1]);
if (x < min)
min = x;
if (x > max)
max = y;
for (int j = x; j < y; j++)
h[j] = 1;
}
i = min;
ans = 0;
while (i < max) {
t = 0;
while (h[i] > 0) {
t++;
i++;
}
if (t > ans)
ans = t;
i++;
}
fileOut.write(ans + " ");
ans = 0;
i = min;
while (i < max) {
t = 0;
while (h[i] == 0) {
t++;
i++;
}
if (t > ans)
ans = t;
i++;
}
fileOut.write(ans + "\n");
fileOut.close();
System.exit(0);
}
}

No comments :