From printed percentage and count pairs, recover the unique total file count that fits every truncated percentage, or report that several fit.
Medium5MathInterviewNo attempts yetTime limit5sMemory limit512 MBA file transfer tool prints a status line while it runs. The line shows the percentage of files transferred so far and the number of files transferred so far:
20% |==>-------| 1 files transferred
100% |==========| 5 files transferred
The percentage is not exact. The tool cuts it off at the decimal point, so both 1.2% and 1.7% print as 1%. Write P for the printed percentage, K for the printed count and F for the total number of files. Every status line then satisfies P=⌊100K/F⌋.
Users asked to see the total as well, so the line should become this:
20% |==>-------| 1 out of 5 files transferred
100% |==========| 5 out of 5 files transferred
The total cannot always be recovered. Given the status lines printed during one transfer, report the total number of files, or report that more than one total fits.
The tool prints status lines at arbitrary moments. It does not print at fixed intervals, and it does not print once per transferred file. A total F fits the status lines when F≥1, every printed count satisfies K≤F (the tool never transfers a file that does not exist), and every printed percentage satisfies P=⌊100K/F⌋.
The first line contains T, the number of test cases. Each test case starts with a line containing N, the number of status lines, followed by N lines. The i-th of them contains two integers Pi and Ki, the percentage and the count printed on that status line. The lines come in chronological order, so within a test case both Pi and Ki are nondecreasing.
For each test case, print one line Case #x: y, where x is the test case number starting from 1 and y is the total number of files. When more than one total fits the status lines, print -1 in place of y.