Lower Bound in a Sorted Array
Find the index of the first element greater than or equal to a given target.
Input format
The first line contains N and the target. The second line contains N integers in non-decreasing order (duplicates allowed).
Output format
Print the smallest index i with a[i] ≥ target. If no such element exists, print N.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
5 4
1 2 4 4 7Expected output
2Example 2
Input
4 10
1 3 5 7Expected output
4