Problems > First Value At Least X

First Value At Least X

Difficulty: 1300 3500 ms 128 MB

binary-search sorting

Sort the array. For each query X, print the 1-based position (in the sorted order) of the first value ≥ X, or −1 if every value is smaller.

Input: the first line has N and Q; the second line has N integers; each of the next Q lines has one query X.

Output: Q lines with the answers.

Constraints:

  • 1 ≤ N, Q ≤ 105
  • |values|, |X| ≤ 109

Sample Tests

Input 1
5 3
1 3 3 7 9
3
8
10
Output 1
2
5
-1
Input 2
1 1
5
5
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.