There is no editorial for this problem, but exists few same solution, for instance: https://www.codechef.com/viewsolution/20215651
This greedy solutions as I see for test:
5 2 3
10 8 4 3 3
will give 13*15 = 195.
But optimal as I see: 14*14 = 196.
Am I right? Does this problem have polynomial solution?