P16430 Crisis Everywhere.

Background

Algo Beat has run into a series of crises. They plan to send several people to resolve the crises in order to ensure national security.

Description

There are $n$ people as candidates to resolve the crisis. However, they will only work seriously if, among the people sent, everyone has the same diligence value $p_i$. You may also perform any number of **upgrade** operations (possibly $0$ times): - Choose an $i\ (1 \le i \le n)$, and spend $w_i$ dollars to increase $p_i$ by $1$. The king wants to select $k$ people to send, but he wants to minimize the total cost, so he asks you, who can program, to help him.

Input Format

The first line contains two integers $n$ and $k$. The second line contains $n$ integers $p_i$, representing the initial diligence values. The third line contains $n$ integers $w_i$, representing the cost required for an upgrade.

Output Format

Output one integer in a single line, representing the minimum cost.

Explanation/Hint

**Subtask #0** is the sample and is worth $0$ points. **Constraints** **This problem uses bundled testdata.** For all testdata, it holds that: - $1 \le n \le 1000$, $1 \le k \le n$, $1 \le p_i \le 10^9$, $1 \le w_i \le 10^9$. ::cute-table{tuack} | Subtask ID | $k$ | Special Property | Score | | :--------: | :------: | :------: | :--: | | $1$ | $=1$ | None | $10$ | | $2$ | $=2$ | None | $20$ | | $3$ | $\leq n$ | A | $10$ | | $4$ | $\leq n$ | B | $10$ | | $5$ | $\leq n$ | None | $50$ | - Special Property A: It is guaranteed that $w_1 = w_2 = \dots = w_n$. - Special Property B: It is guaranteed that $p$ is a permutation of $1 \sim n$. Translated by ChatGPT 5