#P9802. [NERC 2018] Lazyland
[NERC 2018] Lazyland
Background
Translated from Problem L of NERC 2018。
Problem Description
There are people in a city and types of jobs. Each person currently has a job . 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 , you need to spend 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 and , representing people and types of jobs.
The second line contains integers , where is the job currently done by person .
The third line contains integers , where is the time needed to persuade person 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 , , and .
For Sample 1, let citizens , , and take jobs , , and , respectively.
Translated by ChatGPT 5