View Code of Problem 6

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		int max;
		for(int i = 0;i < t;i++) {
			max = 0;
			int n = scanner.nextInt();
			int[][] a = new int[n][2];
			for(int j = 0;j < n;j++) {
				a[j][0] = scanner.nextInt();
				a[j][1] = scanner.nextInt();
				if(a[j][1] - a[j][0] > max) {
					max = a[j][1] - a[j][0];
				}
			}
			boolean isFlag = true;
			for(int j = 0;j < n - 1;j++) {
				if(a[j][0] + max > a[j + 1][0]) {
					isFlag = false;
					break;
				}
			}
			if(isFlag) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 6