Score : 1000 points
You are given a permutation p = (p_1, \ldots, p_N) of \{ 1, \ldots, N \}. You can perform the following two kinds of operations repeatedly in any order:
Find the minimum total cost required to sort p in ascending order.
Input is given from Standard Input in the following format:
N A B p_1 \cdots p_N
Print the minimum total cost required to sort p in ascending order.
3 20 30 3 1 2
20
Shifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).
4 20 30 4 2 3 1
50
One possible sequence of operations is as follows:
Here, the total cost is 20 + 30 = 50.
1 10 10 1
0
4 1000000000 1000000000 4 3 2 1
3000000000
9 40 50 5 3 4 7 6 1 2 9 8
220