atcoder#ABC256E. [ABC256E] Takahashi's Anguish
[ABC256E] Takahashi's Anguish
Score : points
Problem Statement
There are people numbered through . Takahashi has decided to choose a sequence that is a permutation of integers from through , and give a candy to Person , Person , , and Person , in this order. Since Person dislikes Person , if Takahashi gives a candy to Person prior to Person , then Person gains frustration of ; otherwise, Person 's frustration is . Takahashi may arbitrarily choose . What is the minimum possible sum of their frustration?
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
2 3 2
1 10 100
10
If he lets , only Person gains a positive amount of frustration, in which case the sum of their frustration is . Since it is impossible to make the sum of frustration smaller, the answer is .
8
7 3 5 5 8 4 1 2
36 49 73 38 30 85 27 45
57