#P9802. Minimum Persuasion Time in a City

    ID: 22948 Type: Default 1000ms 256MiB

Minimum Persuasion Time in a City

Minimum Persuasion Time in a City

In a city there are n people and k professions. Each person i is currently engaged in a profession denoted by \(a_i\). Unfortunately, due to some missing professions, the city cannot function normally when there is at least one profession that no one is engaged in. As the ruler of the city, you want to persuade some of the people to change their profession so that every one of the k professions is covered.

For each person i, it takes \(b_i\) time to persuade them. However, note that if a person is the only one in their current profession, you should not persuade them because that profession would then become empty. Your task is to choose a set of people to persuade (from those whose current profession is held by more than one person) such that after persuading the selected people, every profession has at least one person, and the total persuasion time is minimized.

Input constraints:

  • \(1 \leq n, k \leq 10^5\)
  • \(1 \leq a_i \leq k\)
  • \(1 \leq b_i \leq 10^9\)

inputFormat

The first line contains two integers n and k, representing the number of people and the number of professions, respectively.

The second line contains n integers \(a_1, a_2, \dots, a_n\), where \(a_i\) denotes the current profession of the i-th person.

The third line contains n integers \(b_1, b_2, \dots, b_n\), where \(b_i\) is the time required to persuade the i-th person.

outputFormat

Output a single integer: the minimum total persuasion time required so that every profession from \(1\) to \(k\) has at least one person working in it.

sample

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