How Many Files
InterviewTime limit5sMemory limit512 MB
From printed percentage and count pairs, recover the unique total file count that fits every truncated percentage, or report that several fit.
- Level
Medium5 of 10
- Topics
- Math
- Solved
- No attempts yet
Problem
A 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 for the printed percentage, for the printed count and for the total number of files. Every status line then satisfies .
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 fits the status lines when , every printed count satisfies (the tool never transfers a file that does not exist), and every printed percentage satisfies .
Input
The first line contains , the number of test cases. Each test case starts with a line containing , the number of status lines, followed by lines. The -th of them contains two integers and , the percentage and the count printed on that status line. The lines come in chronological order, so within a test case both and are nondecreasing.
Limits
- Every test case has at least one total that fits its status lines.
- When exactly one total fits, that total is at most .
Output
For each test case, print one line Case #x: y, where is the test case number starting from 1 and is the total number of files. When more than one total fits the status lines, print -1 in place of .