It's the night before Christmas and bitter old Ebenezer Scrooge has banished the Ghost of Christmas Past from his sight.
Little does he know, this is only the beginning of his plight.
For he will now receive a visit by the Ghost of Christmas Present.
And although old Ebenezer Scrooge is feeling quite irreverent.
The Ghost of Christmas Present shows the old man visions of his secretary's family.
And of little Tiny Tim, a terminally ill boy who still enjoys Christmas happily.
The secretary, Bob Cratchit, is out to buy a turkey for a Christmas feast.
Help him determine the size of turkey he will buy, and it would be a significant feat.
Ebenezer Scrooge's secretary, Bob Cratchit is buying turkeys for his family's Christmas dinner. In order to not be overwhelmed by food, he needs to only buy turkeys that are below a certain size. However, he wants to maximize the size of the turkey while still keeping it below this threshold. Given the maximum sizes of the turkeys he wants to buy as well as the turkeys available, determine which turkeys on sale are the biggest while still being at or below his maximum.
Input Specification
The first line of input contains representing the number of turkeys available in the store.
The next lines each contain an integer representing the size of each turkey available. There is an unlimited number of turkeys of size and each value of is guaranteed to be unique.
The next line contains representing the number of turkeys Bob Cratchit wants to buy.
The next lines each contain an integer representing the maximum size of one of the turkeys Bob wants to buy. The turkey bought must not exceed this size.
Solutions in Java are encouraged to use fast input reading.
Output Specification
For each maximum size, output on a new line the size of turkey Bob Cratchit should buy for it. If no turkey at or below this size exists, output 0
.
Subtasks
Subtask 1
For 3 points, .
Subtask 2
For the remaining 4 points, no additional constraints.
Sample Input
5
1
7
4
11
12
3
5
20
1
Sample Output
4
12
1
Comments
Brüh