Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.
You know it’s hard seeing your favorite person being interested in another one instead of you. At that time, you can do nothing rather than maximize the distance.
Swachha has a sequence of integers and Sumaiya has queries.
In a query, Sumaiya will give you integers and . You have to find a pair of integers and such that
is maximum.
Here, denotes the absolute value of .
The first line of the input contains an integer denotes the number of testcases.
The first line of each testcase contains an integer .
The second line contains space separated integers .
The third line contains an integer denotes the number of queries.
The next lines contain space separated integers .
It is guaranteed that sum of and sum of over all testcases won’t exceed respectively.
For each query, print a pair of integers which fulfills the given conditions. If there are multiple possible pairs, you can print any one.
Input | Output |
---|---|
1 5 1 -3 2 6 9 5 1 5 2 4 3 3 1 3 2 5 | 2 3 2 3 3 3 2 3 2 3 |
Query : Query : Query : These are the maximum possible distances in the given range. |
59% Solution Ratio
AlfehsaniEarliest,
NirjhorFastest, 0.1s
NirjhorLightest, 9.4 MB
sh2018331053Shortest, 1623B
Login to submit
Let's denote prefix sum as Pi=a1+a2+⋯+ai{P_i = a_1 + a_2 + \dots + a_i}Pi=a1+a2+⋯+ai and suffix ...