[Solution] Far Away CodeChef Solution | Solution CodeChef
Problem
Chef has an array of size and an integer , such that for every .
The distance of an array from array is defined as:
Chef wants an array of size , such that and the value is as large as possible, i.e, the distance of from is maximum.
Find the maximum distance for any valid array .
Note: denotes the absolute value of an integer . For example, and .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains two space-separated integers and — the length of array and the limit on the elements of and .
- The second line contains space-separated integers .
Output Format
For each test case, output on a new line the maximum distance of an array from .
Explanation:
Test case : The array having maximum distance from is . Thus the distance is .
Test case : The only array possible is . The distance of this array from is .
Test case : One of the possible arrays having maximum distance from is . Thus the distance is .
No comments:
Post a Comment