First Element Greater Than Or Equal To K
You are given a sorted array of N distinct integers. Your task is to find the index of the first element in the array that is greater than or equal to a given integer K. If no such element exists, output -1.
Array indices are 1-based.
Input
The first line contains two integers N and K, separated by a space. The second line contains N distinct integers, sorted in non-decreasing order, representing the array elements.
Output
Print a single integer: the 1-based index of the first element greater than or equal to K, or -1 if no such element exists.
Constraints
1 <= N <= 1000 -10^9 <= K <= 10^9 Array elements are distinct and sorted in non-decreasing order. -10^9 <= array element <= 10^9
Example 1
5 7 2 3 5 7 9
4
The first element >= 7 is 7, which is at index 4.
Example 2
6 10 1 3 5 8 9 12
6
The first element >= 10 is 12, which is at index 6.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 7 2 3 5 7 9
6 10 1 3 5 8 9 12