#P3955. [NOIP 2017 普及组] 图书管理员
[NOIP 2017 普及组] 图书管理员
Description
Each book in the library has a book code, which is a positive integer, used for quick lookup. Each reader has a request code, also a positive integer. If a book’s code ends with a reader’s request code, then that book is what the reader needs. Xiao D has just become the librarian. She knows the codes of all books in the library and asks you to write a program to, for each reader, find the book with the smallest code among the books they need. If there is no book they need, please output -1.
Input Format
The first line contains two positive integers , separated by a space, representing the number of books in the library and the number of readers, respectively.
The next lines each contain a positive integer, representing the code of a book in the library.
The next lines each contain two positive integers separated by a space. The first integer is the length of the reader’s request code, and the second integer is the reader’s request code.
Output Format
Output lines. For the -th line, if there exists a book needed by the -th reader, output the smallest book code among those books; otherwise, output -1.
5 5
2123
1123
23
24
24
2 23
3 123
3 124
2 12
2 12
23
1123
-1
-1
-1
Hint
Constraints and Notes
For of the testdata, .
For another of the testdata, .
For another of the testdata, the lengths of all readers’ request codes are .
For another of the testdata, all book codes are given in ascending order.
For of the testdata, , and all book codes and request codes do not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号