#P2091. 排序
排序
Description
Little A has objects arranged in a row, each with volume and mass . The volumes of the objects are within and are all distinct, but the masses may be the same.
Now Little A needs to reorder the objects in increasing order of volume. His sorting method is: each operation swaps two objects. Each swap costs the sum of the masses of the two objects.
Little A wants to know the minimum total energy he must spend to sort the objects.
Input Format
The first line contains a positive integer , the number of objects.
The second line contains positive integers; the -th number is the volume of the -th object from left to right.
The third line contains positive integers; the -th number is the mass of the -th object from left to right.
Output Format
Output a single integer, the minimum total energy Little A will spend.
3
1 3 2
2 2 3
5
Hint
| Test Point | ||
|---|---|---|
Translated by ChatGPT 5
京公网安备 11011102002149号