Official algorithmic problem description and constraints.
You are given an array 𝐴 containing 𝑁 integers.
Consider the following process:
Before performing the process, you're allowed to freely rearrange the elements of 𝐴 as you like.
If you choose the rearrangement of 𝐴 and the sequence of operations optimally, what's the maximum possible value of 𝑆 that you can obtain?
This maximum value can be very large, so print it modulo 1^9+7?
Detailed video explanations, mathematical intuition, and clean C++ implementation code.