This function assumes that arr [ ] is sorted in increasing order according the first ( or smaller ) values in pairs .
static int maxChainLength ( Pair [ ] arr , int n ) { int i , j , max = 0 ; int [ ] mcl = new int [ n ] ;