Problem 876
Search Suggestions System
Medium · 20 pts · String, Sorting, Binary Search, Trie
Problem
You are given a list of product names and a search word typed one letter at a time. After each typed letter, suggest at most three products that start with the letters typed so far, choosing the lexicographically smallest ones. Print the suggestions for every prefix, or NONE when no product matches. Sort the products once; then for each prefix, binary search for its first match and look at the next three names.
Input
The first line contains N. The second line contains the N product names. The third line contains the search word. All use lowercase letters.
Output
Print one line per typed letter: up to three suggestions separated by spaces, or NONE.
Constraints
1 <= N <= 1000; 1 <= |name|, |word| <= 1000
Example input
5 mobile mouse moneypot monitor mousepad mouse
Example output
mobile moneypot monitor mobile moneypot monitor mouse mousepad mouse mousepad mouse mousepad
Explanation
For mouse with products mobile mouse moneypot monitor mousepad: after m and mo the three smallest are mobile moneypot monitor; after mou, mous and mouse only mouse and mousepad match.