Marks :10
: 12 | : 1
You have a traditional $$$6$$$-faced dice, and you rolled it $$$M+N$$$ times. The numbers from rolls of $$$M$$$ times are in $$$A$$$, and the numbers from rolls of $$$N$$$ times are in $$$B$$$. You want each array to have a common sum. You can modify the arrays so that their sums are equal, but you should use the minimum number of turns. Through a turn, you can change a value from an array into any value between $$$1$$$ and $$$6$$$. You cannot delete a value or make it $$$0$$$ or negative.
$$$A$$$'s length and $$$B$$$'s length can be different. If it is impossible to make both arrays sum to a common sum, return $$$-1.$$$
The first line contains two integers, $$$n$$$ $$$(1 \le n \le 10^5)$$$ and $$$m$$$ $$$(1 \le m \le 10^5)$$$.
The second line contains $$$n$$$ integers, $$$A_1,A_2,...A_n$$$ $$$(1 \le A_i \le 6)$$$.
The third line contains $$$m$$$ integers, $$$B_1,B_2,...B_m$$$ $$$(1 \le B_i \le 6)$$$.
Return the minimum number of turns required to make the sums equal and $$$-1$$$ if it's impossible.
3 3 1 4 3 6 6 6
2
You need to login to view your submissions.
You need to login to view all submissions.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.