Schedule
Time limit2sMemory limit512 MB
Assign interval tasks to machines so no two overlapping tasks share a machine; minimize the number of machines, then the total working time (earliest start to latest finish) across those machines.
Problem
There are tasks: task has to start at moment and finish at moment . There is a potentially infinite supply of machines. We want to assign tasks to machines. Each task is assigned to one machine. A machine may handle any number of tasks as long as no two of them overlap. Tasks and are said to overlap if the intersection of the open intervals and is non-empty.
A machine is turned on at the moment when the earliest of its assigned tasks has to start, and turned off at the moment when the latest of them has to finish. The working time of a machine is the length of the time period between these two moments: a single machine can be turned on and off only once.
Find the minimum possible number of machines such that we can perform all tasks using only machines. Also, when using machines, find the minimum possible sum of all their working times.
Input
The first line of input contains an integer , the number of test cases ().
Each test case begins with a line containing one integer (). Each of the next lines contains two integers and ().
It is guaranteed that for no more than 10 test cases.
Output
For each test case, print two integers in one line: the minimum possible number of machines to perform all tasks and the minimum sum of all working times when using machines.