Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Maximize the sum

Правка en1, от 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.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский greek__god 2020-07-23 08:08:47 354 Initial revision (published)