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

greek__god's blog

By greek__god, history, 4 years ago, In English

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.

Full text and comments »

  • Vote: I like it
  • +7
  • Vote: I do not like it