[Solution] Magical Array Codeforces Solution
Eric has an array of length , then he generates additional arrays , each of length , from the array , by the following way:
Initially, for every . Eric secretly chooses an integer and chooses to be the special array.
There are two operations that Eric can perform on an array :
- Operation 1: Choose two integers and (), subtract from both and , and add to both and . That operation can only be used on a non-special array, that is when .;
- Operation 2: Choose two integers and (), subtract from both and , and add to both and . That operation can only be used on a special array, that is when .
Note that Eric can't perform an operation if any element of the array will become less than after that operation.
Now, Eric does the following:
- For every non-special array (), Eric uses only operation 1 on it at least once.
- For the special array , Eric uses only operation 2 on it at least once.
Lastly, Eric discards the array .
For given arrays , your task is to find out the special array, i.e. the value . Also, you need to find the number of times of operation was used on it.
The first line contains a single integer () — the number of test cases. Description of test cases follows.
The first line of each test case contains two integers and (, ) — the number of arrays given to you, and the length of each array.
The next lines contains integers each, .
It is guaranteed that each element of the discarded array is in the range , and therefore for all possible pairs of .
It is guaranteed that the sum of over all test cases does not exceed .
It is guaranteed that the input is generated according to the procedure above.
For each test case, output one line containing two integers — the index of the special array, and the number of times that Operation 2 was performed on it. It can be shown that under the constraints given in the problem, this value is unique and won't exceed , so you can represent it as a -bit integer. It can also be shown that the index of the special array is uniquely determined.
In this problem, hacks are disabled.
No comments:
Post a Comment