![]() |
||||||||||
|
||||||||||
Boring TaskTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 85 Accepted Submission(s): 27 Problem Description You are given N tasks numbered from 1 to N and a single machine able to process the tasks. At any time, the machine can only process a single task. For every integer i between 1 and N, you are given 2 integers - $T_i$, denoting when the $i^{th}$ task is created, that means you can only process the $i^{th}$ task not earlier than $T_i$, and $D_i$, denoting the period of time the machine takes to completely process the $i^{th}$ task. All the tasks are individual, so you can assign tasks in any order. Also, if the machine starts to process a task, then it never stops working until the task is finished. The machine can immediately start the other task (obviously, this task should be available) after finishing a task. The waiting time, for the $i^{th}$ task, is defined as the delay time of the task that is equal to the difference between the time when the machine starts to process the $i^{th}$ task and $T_i$. You want to minimize the maximum waiting time of the given tasks. Find the minimum value of maximum waiting time. Input The first line of the input contains a single integer T (1≤T≤1 200), the number of test cases. Each test case consists of 3 lines. The first line of each test case contains a single integer N (1≤N≤$2 \cdot {10^5}$), the number of tasks. The next line contains N integers $T_i$ (1≤$T_i$≤$2 \cdot {10^{14}}$), the earliest time the $i^{th}$ task can be processed. The $3^{rd}$ line N integers $D_i$ (1≤$D_i$≤$10^9$), the period of time the machine takes to finish the $i^{th}$ task. It’s guaranteed that the sum of N over all test cases doesn’t exceed 2 500 000. Output For each test case, you should print the minimum possible value of the maximum waiting time. Sample Input
Sample Output
Source | ||||||||||
|