Sausage Slinger
Rory is an innovator... a prodigy... a trend-setter...
He is looking for the next big opportunity or gap in the market to make insane profits before he can sell all of his equity to run a goose farm in Mildura.
Rory has decided to try out sausage slinging (selling hotdogs) at orientation week this year.
Unfortunately for Rory, he doesn't have anyone to serve in his hotdog stand while he chefs up a storm. To compensate, Rory will hurl the sausages from his trailer window into the queue of first-year students keen for a feed!
Rory wants to know which student received each sausage. If he can throw them well enough he won't need any helpers to serve his hotdogs, allowing him to skyrocket his profits.
Input
The first line consists of an integer
, the number of career expo-goers currently in the sausage queue.
The second line consists of space-separated integers,
, where each
represents the positions of each career expo-goer in the queue. The student positions are unique and sorted in ascending order.
represents the front most position in the line, infront of the hotdog stall.
The third line consists of an integer
, denoting the number of hotdogs to be served.
The fourth line consists of space-separated integers,
, where each
is the random service position for hotdog
.
Output
For each hotdog to be served, return the position of the customer who will receive the randomly allocated hotdog.
If the service position is larger than a customers position, the hotdog will go to the next person in the line. Formally, if , then
cannot receive the hotdog;
will receive hotdog
when
and
.
If the hotdog positon has no customer to receive it, output
.
Output each new receival position on a new line.
Example
Input 1
3
0 3 6
3
1 3 5
Output 1
3
3
6

- The first hotdog flew over the student at position
and was collected by the student at position
, because there was no prior student with a position
- The second hotdog landed on the student at position
.
- The final hotdog flew over the student at position
but was collected by the student at position
.
Input 2
1
1
2
1 3
Output 2
1
-1
The first hotdog was received by the student at position , however, the second hotdog was thrown to a position with no student to collect it.
Comments