#B4071. Weapon Enhancement Optimization

    ID: 11728 Type: Default 1000ms 256MiB

Weapon Enhancement Optimization

Weapon Enhancement Optimization

Little Yang has \(n\) kinds of weapons and \(m\) kinds of enhancement materials. The \(i\)-th material is originally adapted to weapon \(p_i\). By spending \(c_i\) gold coins, he can change the adapted weapon of that material to any weapon of his choice.

Since Little Yang favors weapon 1 above all, he wants the number of materials adapted to weapon 1 to be strictly greater than that of any other weapon. Calculate the minimum total gold coins he must spend to achieve this.

Note: All formulas are represented in \(\LaTeX\) format.

inputFormat

The first line contains two integers \(n\) and \(m\) (the number of weapons and materials).

The second line contains \(m\) integers \(p_1, p_2, \ldots, p_m\), where \(p_i\) denotes the weapon to which the \(i\)-th material is originally adapted.

The third line contains \(m\) integers \(c_1, c_2, \ldots, c_m\), where \(c_i\) denotes the cost in gold coins to change the adaptation of the \(i\)-th material.

outputFormat

Output a single integer, the minimum total cost required so that the number of materials adapted to weapon 1 is strictly greater than the number of materials adapted to any other weapon.

sample

3 5
1 2 2 3 1
5 1 2 3 4
1