![]() |
||||||||||
|
||||||||||
BilibiliTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2 Accepted Submission(s): 1 Problem Description Cdfpysw loves to watch videos at bilibili.com. When he watch videos, he can write some comments, and they will be shown on his screen. His screen has size of n * m, and every word has size of 1 * 1. When Cdfpysw send a comment, it'll be shown on the rightmost of the topmost line which doesn't contain any comment. If there are comments in all lines, this comment will be failed to send. Every second, the comments on the screen will be shifted to left for 1 before the new comments be send. e.g.: Now, the following picture is the screen. Cdfpysw wants to write 3 comments at now, 1 second later, and 6 seconds later. They will be shown on the 2nd line, 5th line, and 1st line. ![]() This example is NOT same as the sample below! Now Cdfpysw wants to know his comments would be shown on which line, if the comment is failed to send, print "Failed!". Input The first line is an integer T, means the number of cases. For each case The first line contains 3 integers, n, m, q, means the size of screen and the number of comments Cdfpysw wants to send. Then q lines, for each line, there are 2 integers t, l, means the sending time and the length of the comment. It is guaranteed that t is in ascending order. T <= 10 1 <= n, m, q <= 50000 0 <= t <= 109 1 <= l <= 109 Output For each case, you should print "Case #i:" in a line, i is the case number. Then q lines, each line contains an integer to represent the line to show the comment or a string "Failed!" to represent the comment is failed to send. Sample Input
Sample Output
Source | ||||||||||
|