Codeforces #87 div2 A "Tram"

問題:http://codeforces.com/contest/116/problem/A

出入りの回数とそれぞれの出入りの人数が与えられる.出入りが行われた中で最大となったときの人数を求める.

シミュレートしてその間での最大を取っておくだけ.

import java.util.*;

public class A {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt(), x = 0, max = 0;
		for (int i = 0; i < n; ++i) {
			x -= s.nextInt();
			x += s.nextInt();
			max = Math.max(max, x);
		}
		System.out.println(max);
	}
}