Function to find lower_bound
function LowerBound ( a , k , x ) { var l = - 1 ; var r = k ; while ( l + 1 < r ) { var m = ( l + r ) >>> 1 ; if ( a [ m ] >= x ) { r = m ; } else { l = m ; } } return r ; }