#P9802. [NERC 2018] Lazyland

[NERC 2018] Lazyland

Background

Translated from Problem L of NERC 2018

Problem Description

There are nn people in a city and kk types of jobs. Each person currently has a job aia_i. Unfortunately, because some jobs are vacant, the city cannot continue to function normally.

As the ruler of the city, you do not want to see this happen. You decide to persuade some people so that every job has at least one person doing it. For each person ii, you need to spend bib_i time to persuade them.

You need to find the minimum total time you have to spend on persuading.

Input Format

The first line contains two integers nn and kk (1kn105)(1 \leq k \leq n \leq 10^5), representing nn people and kk types of jobs.

The second line contains nn integers aia_i (1aik)(1 \leq a_i \leq k), where aia_i is the job currently done by person ii.

The third line contains nn integers bib_i (1bi109)(1 \leq b_i \leq 10^9), where bib_i is the time needed to persuade person ii to do a different job.

Output Format

Output the minimum total time needed to persuade the citizens.

8 7
1 1 3 1 5 3 7 1
5 7 4 8 1 3 5 2
10
3 3
3 1 2
5 3 4
0

Hint

For all testdata, it is guaranteed that 1kn1051 \leq k \leq n \leq 10^5, 1aik1 \leq a_i \leq k, and 1bi1091 \leq b_i \leq 10^9.

For Sample 1, let citizens 11, 66, and 88 take jobs 22, 44, and 66, respectively.

Translated by ChatGPT 5