Please read the new rule regarding the restriction on the use of AI tools. ×

Maximize the sum

Revision en1, by greek__god, 2020-07-23 08:08:47

Given array A of size n we have to create an array B by re-arranging array A. Now we need to maximize the sum $$$|A_i - B_i|$$$. I think sorting A in increasing and B in decreasing order then adding corresponding element will result in optimal solution. Is this correct or there can be a better algorithm for this problem. Thanks in advance.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English greek__god 2020-07-23 08:08:47 354 Initial revision (published)