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();
        while (t-->0){
            int n=scanner.nextInt();
            int[][] trap=new int[n][2];
            int max=0;
            for(int i=0;i<n;i++){
                trap[i][0]=scanner.nextInt();
                trap[i][1]=scanner.nextInt();
                if(max<Math.abs(trap[i][0]-trap[i][1])){
                    max=Math.abs(trap[i][0]-trap[i][1]);
                }
            }
            String ans="YES";
            for(int i=0;i<trap.length-1;i++){
                if(trap[i][0]+max>trap[i+1][0]){
                    ans="NO";
                    break;
                }
            }
            System.out.println(ans);
            
        }
    }
}

Double click to view unformatted code.


Back to problem 6