Dividing array greedy

output is correct thn also test cases are not passing

hello @nmaurya760

a) first sort ur arr array after taking input

b) use long long in place of int

image

Still test cases are not passing

check i have updated my reply.

ur logic for max is correct,
of min u need to take sum of difference of consecutive pairs of original array .

For min if we will subtract maximum values of both the arrays we will get the answer??

no,
for minimum, difference between pairs should be less right?
and how is it possible?
it is possible only when we pick consective pairs (consective pairs will have least difference) of original sorte array.

What i have done is that i have sorted both the parts of array in descending order and then i am taking their absolute difference

yeah i have seen that,
if u pick a[i] from ur array then for mimimum i need to pick a[i+1] for minimum because they are closest with eacch other,but u r picking a[i] and b[i] which is wrong.

pls pick some test cases and dry run on it.

also i have shared the forumla in very first response so plc check that