Please Write the If Statements for Me
Time limit1sMemory limit1024 MB
Given N titles ordered by increasing power upper bounds, print for each of M power values the first title whose bound is at least that value.
- Level
Easy3 of 10
- Topics
- Binary search, Array, Implementation, Sorting
- Solved
- No attempts yet
Problem
Millie, a game developer, is building a combat power system and wants to assign titles to characters based on their combat power.
For example, suppose a character with combat power 10,000 or less gets the title WEAK, a character with combat power greater than 10,000 and at most 100,000 gets NORMAL, and a character with combat power greater than 100,000 and at most 1,000,000 gets STRONG. Written with if statements, this can be implemented as follows.
if power <= 10000
print WEAK
else if power <= 100000
print NORMAL
else if power <= 1000000
print STRONG
Millie is very busy developing the game alone. Write a program that prints the title matching each character's combat power in her place.
Input
The first line gives the number of titles N (1 ≤ N ≤ 105) and the number of characters whose titles must be printed M (1 ≤ M ≤ 105), separated by a space. (1 ≤ N, M ≤ 105)
Each of the next N lines gives a string of 1 to 11 uppercase English letters, the name of a title, and a non-negative integer at most 109, the upper bound of combat power for that title. The titles are given in non-decreasing order of their combat power upper bounds.
Each of the M lines starting from line N + 2 gives a non-negative integer, the combat power of a character. No combat power without a matching title is given in the input.
Output
Over M lines, print the title matching each character's combat power in input order. If a character's combat power matches several titles, print only the one that was given first.