The Scariest Story (Basic)
InterviewTime limit1sMemory limit1024 MB
Given a story of n words and m global character positions, print the word number and the character's position within that word for each position.
- Level
Easy3 of 10
- Topics
- Prefix sum, Binary search
- Solved
- No attempts yet
Problem
Little Jack wants to write the scariest story to frighten his friends on Halloween.
A story is a non-empty sequence of words separated by spaces. A word is a non-empty sequence of lowercase Latin letters.
The quality of a story depends not only on the words in it but also on the characters in those words.
Jack has already written a story of words. Now he wants to test hypotheses about it to confirm that it is really scary. For each hypothesis, he must find, given the position of a character in the story, the number of the word that contains it and the position of that character within the word.
Input
The first line contains two integers and separated by a space, the number of words in the story and the number of hypotheses (; ).
The next line contains the story: words of lowercase Latin letters separated by spaces. The total length of all words does not exceed .
The last line contains integers separated by spaces, the character positions in the hypotheses ().
Output
Print pairs of numbers, one pair per line. The pair on line is the number of the word that contains the -th character and the number of that character within the word. Words and characters are numbered from 1.