text: returns the upper bound
code: static int upperbound ( int [ ] a , int n , int value ) { int low = 0 ; int high = n ; while ( low < high ) { int mid = ( low + high ) / 2 ; if ( value >= a [ mid ] ) low = mid + 1 ; else high = mid ; } return low ; }