|
|
вернуться в форумsolution Послано Wonsei 19 сен 2020 04:20 sort the array. maintain W, the total weight of the array. start from the smallest element and add A[i] * W to ANS. subtract A[i] from W. add A[i] * W again. Re: solution Послано Egor 20 сен 2020 21:49 There is a better solution with O(1) memory and O(n) time (without sorting). Edited by author 20.09.2020 21:51 Edited by author 20.09.2020 21:51 Re: solution Do you mind sharing this solution? I solved it using sorting but cannot think of another solution. Re: solution answer = (sum of array) ^ 2 You can get it by simple math. Do you mind sharing this solution? I solved it using sorting but cannot think of another solution. |
|
|