Rayan and Sarah each hike along a trail. Each trail has N checkpoints numbered 1 to N. The starting point (checkpoint 0) is at altitude 0 for both trails.
Rayan's trail has altitudes p1,p2,…,pN at each checkpoint. Sarah's trail has altitudes q1,q2,…,qN.
The slope of a segment from checkpoint i to checkpoint j is:
s(i,j)=j−iaj−ai
They want to divide their trails into the same number of segments k (but they can use different breakpoints):
- Rayan's segments: 0=u0<u1<…<uk=N
- Sarah's segments: 0=v0<v1<…<vk=N
For each segment pair m (from 1 to k), the following must hold:
s(P,um−1,um)+X≤s(Q,vm−1,vm)
Find the maximum value of X for which a valid partition exists.
Constraints
- 1≤t≤10
- 1≤N≤400
- −109≤pi,qi≤109
- The sum of N over all test cases does not exceed 500.