In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of October 26th
(this exercise will still be available for submission after that deadline, but without couting towards your grade)
[to understand the context of this problem, you should read the class #03 exercise sheet]
Tom needs your help again!
Given a sorted sequence of N integer numbers and Q queries, each one indicating a number to search for, your task is to find the position of the first number in the sequence that is bigger or equal than the query number (or to find that all numbers are lower).
The first line of input contains an integer N, the quantity of numbers in the sorted sequence. The second line contains the sequence itself with N space separated integers (we denote each one by Si). It is guaranteed that these come in increasing order, but there might be repeated numbers.
The third line contains an integer Q, the quantity of queries to consider. Each of the following Q lines contains a query in the form of a single integer Xi, indicating the number we are querying.
The output should contain exactly Q lines. The i-th line should contain the position of the first number in the sequence that is bigger or equal than Xi or -1 if all sequence numbers are smaller than Xi. Note that the positions in the sequence go from 0 to N-1.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ N ≤ 105 | Quantity of numbers in the sequence | |
1 ≤ Si ≤ 109 | Numbers in the sorted sequence | 1 ≤ Q ≤ 105 | Quantity of queries |
1 ≤ Xi ≤ 109 | Numbers that will be queried |
Example Input | Example Output |
10 2 2 2 3 5 5 8 8 8 8 6 2 8 5 1 4 9 |
0 6 4 0 4 -1 |
Explanation of the example: