View Code of Problem 6

import java.awt.event.WindowFocusListener;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner Sc = new Scanner(System.in);
        int T = Sc.nextInt();

        for (int i = 0; i < T; i++) {
            int n = Sc.nextInt();
            if (n > 100)
                break;


            int[][] arr = new int[n][2];
            int max = 0;


            for (int j = 0; j < n; j++) {
                arr[j][0] = Sc.nextInt();
                arr[j][1] = Sc.nextInt();


                if (max < Math.abs(arr[j][0] - arr[j][1])) {
                    max = Math.abs(arr[j][0] - arr[j][1]);

                }
            }
            int X = 0;
            for (int j = 0; j < n - 1; j++) {
                if (arr[j][0] + max > arr[j][1]) {
                    X = 1;
                }


            }
            if (X == 1) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        }
    }
}

Double click to view unformatted code.


Back to problem 6