Score : $500$ points
Takahashi has come to a party as a special guest. There are $N$ ordinary guests at the party. The $i$-th ordinary guest has a power of $A_i$.
Takahashi has decided to perform $M$ handshakes to increase the happiness of the party (let the current happiness be $0$). A handshake will be performed as follows:
However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:
What is the maximum possible happiness after $M$ handshakes?
Input is given from Standard Input in the following format:
$N$ $M$ $A_1$ $A_2$ $...$ $A_N$
Print the maximum possible happiness after $M$ handshakes.
5 3 10 14 19 34 33
202
Let us say that Takahashi performs the following handshakes:
Then, we will have the happiness of $(34+34)+(34+33)+(33+34)=202$.
We cannot achieve the happiness of $203$ or greater, so the answer is $202$.
9 14 1 3 5 110 24 21 34 5 3
1837
9 73 67597 52981 5828 66249 75177 64141 40773 79105 16076
8128170