You are given an array $a$ of $n$ positive integers. You can change the $i^{th}$ element in the array to any value you want. The cost of this operation is $c_i$.
You are given $q$ independent queries. For each query, you are given an integer $m$ and your task is to find the minimum total cost needed to make $m$ the most frequent number of the array. No other value should have the same frequency as $m$.
The first line of the input contains two integers $n$ and $q$ ($1 \le n \le 2 \times 10^5$, $1 \le q \le 500$), the size of an array, and the number of queries.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), the elements of array $a$.
The third line contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 10^9$), where $c_i$ is the cost of changing the $i^{th}$ element to any other value.
The last line contains $q$ integers $m_1, m_2, \dots, m_q$ ($1 \le m_i \le 10^9$), where $m_i$ is the most frequent number for the $i^{th}$ query.
Print a single line with $q$ integers, the $i^{th}$ integer is the minimum total cost to make $m_i$ the most frequent element of the array.
Input | Output |
---|---|
7 3 9 6 4 4 9 7 9 3 17 2 15 5 2 4 9 5 6 Copy
|
0 7 5 Copy
|