F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Boring Task

Time 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
2 3 1 3 2 1 1 1 3 1 3 2 3 2 1
 

Sample Output
0 2
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-25 19:51:11, Gzip enabled