#P1678. 烦恼的高考志愿

烦恼的高考志愿

Description

There are mm schools, each with an expected cutoff score aia_i. There are nn students, with estimated scores bib_i.

Based on the estimated scores of the nn students, recommend one school to each student such that the difference between the school’s expected cutoff score and the student’s estimated score is minimized (either higher or lower—after all, it’s just an estimate). This minimum difference is called dissatisfaction. Find the minimum possible sum of dissatisfaction over all students.

Input Format

The first line contains two integers m,nm, n.

The second line contains mm numbers, representing the expected cutoff scores of the mm schools.

The third line contains nn numbers, representing the estimated scores of the nn students.

Output Format

Output one line, the minimum sum of dissatisfaction.

4 3
513 598 567 689
500 600 550

32

Hint

Constraints:

For 30%30\% of the testdata, 1n,m1031 \le n, m \le 10^3, and the estimated scores and cutoffs are 104\le 10^4.

For 100%100\% of the testdata, 1n,m1051 \le n, m \le 10^5, the estimated scores and cutoffs are 106\le 10^6, and all are non-negative integers.

Translated by ChatGPT 5