View Code of Problem 6

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {	
		Scanner scan = new Scanner(System.in);
		int count = scan.nextInt();
		int max=0;
		boolean flag=true;
		for(int i=0;i<count;i++) {
			int num = scan.nextInt();
			int[] l = new int[num];
			int[] r = new int[num];
			for(int j=0;j<num;j++) {
				l[j] = scan.nextInt();
				r[j] = scan.nextInt();
				max = Math.max(r[j] - l[j], max);
			}
			for(int k=0;k<num-1;k++) {
				if(l[k]+max>l[k+1]) {
					flag = false;
				}
			}
			if(flag) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
			max = 0;	
		}
		scan.close();
		}
}

Double click to view unformatted code.


Back to problem 6