[Solution] Make A and B equal CodeChef Solution
Problem
Chef is given two arrays and of length each.
In one operation Chef can choose one element of and one element of and increase them by .
More formally: Chef can pick two integers and increment and by .
Determine the minimum number of operations required to make and equal.
Output if it is not possible to make and equal.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer - denoting the length of arrays and .
- The second line of each test case contains space separated integers - denoting the array .
- The third line of each test case contains space separated integers - denoting the array .
Output Format
For each test case, output the minimum number of operations to make and equal or if they cannot be made equal.
Explanation:
Test case : We can choose and and increment and by . Thus, both arrays become and are equal. We require only operation to make these arrays equal. It can be proven that the arrays cannot be made equal in less than one operation.
Test case : Both the arrays cannot be made equal using any number of operations.
Test case : We perform operations as follows:
- Choose : The arrays become and .
- Choose : The arrays become and .
Thus, both arrays can be made equal using operations.
No comments:
Post a Comment