LCC '21 Contest 1 J2 - Spooky Words

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Peter's parents have asked him to put up decorations around his house for Halloween. So, Peter decides to print out some of his favorite words from a list of N spooky words and tape them to the walls.

However, Peter has discovered that the public printer he uses charges less money to print shorter words. The printer considers a word to be shorter than another if it has a smaller length or if they have the same length and it is smaller lexicographically.

Peter wants to be charged as little as possible for his word choices while still keeping the words diverse. To decide which words to use, he will ask you Q questions, where the ith question asks for the K_ith shortest word in the list.

Please help Peter with his Halloween decorations by finding the Q words that he asks for.

Input Specification

The first line will contain two space-separated integers, N (1 \leq N \leq 100) and Q (1 \leq Q \leq N).

The next N lines will each contain a string S_i (1 \leq |S_i| \leq 100) composed of only lowercase English letters, representing the ith word in Peter's list.

The next Q lines will each contain a single integer K_i (1 \leq K_i \leq N), representing the ith question Peter asks.

Output Specification

Output Q lines containing the answers to Peter's questions.

Sample Input

3 2
boo
witch
ghost
1
2

Sample Output

boo
ghost

Comments

There are no comments at the moment.