atcoder#ABC149E. [ABC149E] Handshake
[ABC149E] Handshake
Score : points
Problem Statement
Takahashi has come to a party as a special guest. There are ordinary guests at the party. The -th ordinary guest has a power of .
Takahashi has decided to perform handshakes to increase the happiness of the party (let the current happiness be ). A handshake will be performed as follows:
- Takahashi chooses one (ordinary) guest for his left hand and another guest for his right hand ( and can be the same).
- Then, he shakes the left hand of Guest and the right hand of Guest simultaneously to increase the happiness by .
However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:
- Assume that, in the -th handshake, Takahashi shakes the left hand of Guest and the right hand of Guest . Then, there is no pair such that .
What is the maximum possible happiness after handshakes?
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible happiness after handshakes.
5 3
10 14 19 34 33
202
Let us say that Takahashi performs the following handshakes:
- In the first handshake, Takahashi shakes the left hand of Guest and the right hand of Guest .
- In the second handshake, Takahashi shakes the left hand of Guest and the right hand of Guest .
- In the third handshake, Takahashi shakes the left hand of Guest and the right hand of Guest .
Then, we will have the happiness of .
We cannot achieve the happiness of or greater, so the answer is .
9 14
1 3 5 110 24 21 34 5 3
1837
9 73
67597 52981 5828 66249 75177 64141 40773 79105 16076
8128170