Processor
Time limit1sMemory limit128 MB
Find the smallest integer processor speed that lets every preemptive job finish between its release time and deadline.
- Level
Medium7 of 10
- Topics
- Binary search, Greedy, Heap, Sorting
- Solved
- No attempts yet
Problem
A processor supports dynamic speed scaling: it can run at any positive integer speed, but a higher speed draws more power. To run a set of programs energy-efficiently, we want a schedule that minimizes the maximum speed the processor ever uses.
The processor must run programs. Each program has a release time , a deadline , and an amount of work . All of the work must be performed inside the interval . The processor is preemptive: it may pause the running program and later resume it from the exact point where it stopped, so a program need not run over one contiguous interval. If runs at a constant speed , it finishes in time. The processor runs at most one program at any instant and may change speed over time, but only at positive integer speeds. Speed is unbounded, so every program can always be completed.
Find a schedule that completes all programs and minimizes the maximum speed at which the processor runs.
For example, take five programs with intervals and work : with , with , with , with , and with . The figure below shows a schedule whose maximum speed is , which is optimal for this instance.

Figure 1
Input
The first line contains the number of test cases ().
Each test case starts with a line containing an integer (), the number of programs. Each of the next lines contains three integers , , and : the release time, the deadline, and the work of program , where and .
Output
For each test case, print exactly one line: the minimum possible value of the maximum speed, taken over all schedules that complete every program on time.