#abc256e. E - Takahashi's Anguish
E - Takahashi's Anguish
Score : points
问题描述
设有 名编号为 到 的人。
高桥决定选择一个整数序列 ,该序列是 到 的一个排列,并按照顺序将糖果送给第 号、第 号、 和第 号的人。
由于第 号人不喜欢第 号人,如果高桥在送给第 号人糖果之前先送给第 号人,则第 号人的沮丧值为 ;否则,第 号人的沮丧值为 。
高桥可以任意选择序列 。请问他们的沮丧值之和的最小可能值是多少?
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
3
2 3 2
1 10 100
Sample Output 1
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 .
Sample Input 2
8
7 3 5 5 8 4 1 2
36 49 73 38 30 85 27 45
Sample Output 2
57
update @ 2024/3/10 10:53:56