#P2127. 序列排序
序列排序
Description
Xiao C has an integer sequence of numbers, in which all numbers are pairwise distinct.
Each time, Xiao C can swap any two numbers in the sequence, with a cost equal to the sum of those two numbers.
Xiao C wants to sort the entire sequence in ascending order. What is the minimal cost needed?
Input Format
The first line contains an integer .
The second line contains integers, representing Xiao C's sequence.
Output Format
Output one line containing an integer, the minimal cost Xiao C needs.
6
8 4 5 3 2 7
34
Hint
- For of the testdata, .
- For of the testdata, , and the integers on the second line are positive integers not exceeding .
Translated by ChatGPT 5
京公网安备 11011102002149号