#agc062b. [agc062_b]Split and Insert

[agc062_b]Split and Insert

[English Translation]

Problem Statement

There is a permutation A=(A1,A2,dots,AN)A=(A_1,A_2,\\dots,A_N) of the integers from 11 to NN. Initially, we have Ai=i(1leqileqN)A_i=i\\ (1\\leq i \\leq N).

Takahashi will perform the following operation on this sequence KK times.

  • Choose an integer kk such that 0leqk<N0 \\leq k < N. Take the last kk terms of AA and insert them among the first NkN-k. More precisely, replace AA with any permutation AA' of the NN integers that satisfies the following conditions.
    • (A1,A2,dots,ANk)(A_1,A_2,\\dots,A_{N-k}) is a (not necessarily contiguous) subsequence of AA'.
    • (ANk+1,ANk+2,dots,AN)(A_{N-k+1},A_{N-k+2},\\dots,A_{N}) is a (not necessarily contiguous) subsequence of AA'.

The cost of the series of operations is sumi=1KkiCi\\sum_{i=1}^{K}k_iC_i, where kik_i is the kk chosen in the ii-th operation.

Takahashi wants to perform KK operations so that A=(P1,P2,dots,PN)A=(P_1,P_2,\\dots,P_N) afterward.

Determine whether it is possible to perform such a series of operations. If it is possible, find its minimum cost.

Constraints

  • 2leqNleq1002 \\leq N \\leq 100
  • 1leqKleq1001 \\leq K \\leq 100
  • 1leqCileq1091 \\leq C_i \\leq 10^9
  • (P1,P2,dots,PN)(P_1,P_2,\\dots,P_N) is a permutation of the integers from 11 to NN.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN KK C1C_1 C2C_2 dots\\dots CKC_K P1P_1 P2P_2 dots\\dots PNP_N

Output

If it is impossible to perform KK operations so that A=(P1,P2,dots,PN)A=(P_1,P_2,\\dots,P_N) holds afterward, print -1. If it is possible, print the minimum cost of such a series of operations.


Sample Input 1

4 1
3
3 1 2 4

Sample Output 1

6

By choosing k=2k=2, and inserting A3=3A_3=3 before A1,A2A_1,A_2 and A4=4A_4=4 after A1,A2A_1,A_2, we can make A=(3,1,2,4)A=(3,1,2,4), which satisfies A=(P1,P2,P3,P4)A=(P_1,P_2,P_3,P_4). The cost of this operation is 2timesC1=62 \\times C_1 = 6.

It can be proved that the minimum cost of performing operations so that A=(P1,P2,P3,P4)A=(P_1,P_2,P_3,P_4) afterward is 66.


Sample Input 2

4 1
3
4 3 2 1

Sample Output 2

-1

It is impossible to perform operations so that A=(P1,P2,P3,P4)A=(P_1,P_2,P_3,P_4) afterward.


Sample Input 3

20 10
874735445 684260477 689935252 116941558 915603029 923404262 843759669 656978932 286318130 255195090
11 15 20 10 6 8 18 2 12 4 9 13 19 3 16 7 14 17 5 1

Sample Output 3

7372920743