You are given an array
containing integers, and a positive integer . Find the maximum value of
across all pairs .
Note that refers to the smallest non-negative integer obtained as the remainder upon dividing by . For example, and .
Input Format
- The first line of input will contain a single integer , the number of test cases. The description of test cases follows.
- Each test case consists of two lines of input.
- The first line of each test case contains two space-separated integers and .
- The second line of each test case contains space-separated integers .
Output Format
- For each test case, output on a new line the maximum value of .
Constraints
- The sum of across all test cases won't exceed .
Subtasks
- Subtask 1 (10 points):
- The sum of across all test cases won't exceed
- Subtask 2 (20 points):
- Subtask 3 (70 points):
- Original constraints
Sample Input 1
4
2 18
12 1
3 5
4 5 6
5 4
79 29 80 58 80
3 20
33 46 56
Sample Output 1
24
15
162
112
Explanation
Test case : There are possible pairs of indices to choose from. Their respective values are:
- , giving
- , giving
- , giving
- , giving
Of these, the largest value is .
Test case : There are choices for pairs . Of these, one way to achieve the maximum is by choosing , giving .
Test case : Picking gives a value of , which is the largest possible.
Test case : Picking gives a value of , which is the largest possible.
No comments:
Post a Comment