Java calculates the maximum number of non-intersection intervals (for example, the number of customers who have made the most appointments within one day)
Import java. util. collections;
Public class Tesww {
Public static void main (String [] args ){
Internal reader = new external (System. in );
Int n = reader. nextInt ();
Int [] [] a = new int [n] [2];
For (int I = 0; I For (int j = 0; j <2; j ++ ){
A [I] [j] = reader. nextInt ();
}
}
Sort (a, n); // Sort by the right boundary of the range Hu
Int count = 1;
Int [] [] result = new int [n] [2];
Int max = a [0] [1];
Result [0] [1] = a [0] [1];
Result [0] [0] = a [0] [0];
For (int I = 1; I If (a [I] [0] Continue;
}
Else {
Max = a [I] [1];
Result [count] [0] = a [I] [0];
Result [count] [1] = a [I] [1];
Count ++;
}
}
System. out. println ("up to" + count + "non-repeating intervals :");
For (int I = 0; I System. out. println ("[" + result [I] [0] + "" + result [I] [1] + "]");
}
}
Public static void Sort (int [] [] a, int n ){
For (int I = 0; I For (int j = I; j If (a [j] [1] int temp [] = new int [2];
Temp = a [j];
A [j] = a [I];
A [I] = temp;
}
}
}
}
}