1706: Up the Stairs
Memory Limit:64 MB
Time Limit:1.000 S
Judge Style:Text Compare
Creator:
Submit:2
Solved:2
Description

Input
One line with a positive number: the number of test cases. Then for each test case:
- One line with three numbers N, F, B with 1 ≤ N,F ≤ 1000 and 1 ≤ B ≤ 1000000: the number of persons, the number of floors (0=ground floor, F=penthouse) and the number of boxes that are still on the ground floor.
- N lines with two numbers fi and bi with 0 ≤ fi ≤ F and bi = 0 or bi = 1: the floors where the persons are initially and whether or not they have a box in their hands (1=box, 0=no box).
Output
One line with the amount of time (in minutes) it will take to get all the remaining boxes to the penthouse.
Sample Input Copy
2
3 10 5
0 0
0 0
0 0
2 5 1
2 1
3 0
Sample Output Copy
30
8