##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
You are given an array of positive integers.
In one operation, you may choose an adjacent pair such that , and swap their positions. You may perform this operation any number of times.
Let be the set of all arrays reachable from through these operations. Your goal is to maximize the sum of the first elements:
Find this maximum value.
The only eligible swap is between the first two elements (since ), but swapping them leaves the sum unchanged at . The third element cannot be swapped with because , so is optimal.
Start with and swap with (since ) to obtain , giving a sum of .
Initially the sum is . Swapping with (since ) yields , giving a sum of .
Initially the sum of the first four elements is . Swap with (since ) to obtain , giving a sum of .
Initially the sum of the first four elements is . Swap with (since ) to obtain , giving a sum of .