Under construction

Still being built. Things may change

Processor

Time limit1sMemory limit128 MB

Summary
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 nn programs. Each program PiP_i has a release time rir_i, a deadline did_i, and an amount of work wiw_i. All of the work wiw_i must be performed inside the interval [ri,di][r_i, d_i]. 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 PiP_i runs at a constant speed ss, it finishes in wi/sw_i / s 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 [ri,di][r_i, d_i] and work wiw_i: [1,4][1, 4] with w1=2w_1 = 2, [3,6][3, 6] with w2=3w_2 = 3, [4,5][4, 5] with w3=2w_3 = 2, [4,7][4, 7] with w4=2w_4 = 2, and [5,8][5, 8] with w5=1w_5 = 1. The figure below shows a schedule whose maximum speed is 22, which is optimal for this instance.

Figure 1

Input

The first line contains the number of test cases TT (1≤T≤201 \le T \le 20).

Each test case starts with a line containing an integer nn (1≤n≤100001 \le n \le 10000), the number of programs. Each of the next nn lines contains three integers rir_i, did_i, and wiw_i: the release time, the deadline, and the work of program PiP_i, where 1≤ri<di≤200001 \le r_i < d_i \le 20000 and 1≤wi≤10001 \le w_i \le 1000.

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.

Examples3

  1. Example 1

    Input
    3
    5
    1 4 2
    3 6 3
    4 5 2
    4 7 2
    5 8 1
    6
    1 7 25
    4 8 10
    7 10 5
    8 11 5
    10 13 10
    11 13 5
    8
    15 18 10
    20 24 16
    8 15 33
    11 14 14
    1 6 16
    16 19 12
    3 5 12
    22 25 10
    
    Expected output
    2
    5
    7
    
  2. Example 2

    Input
    1
    1
    1 3 5
    
    Expected output
    3
    
  3. Example 3

    Input
    1
    2
    8 15 33
    11 14 14
    
    Expected output
    7