#P1678. School Recommendation - Minimizing Total Dissatisfaction

    ID: 14964 Type: Default 1000ms 256MiB

School Recommendation - Minimizing Total Dissatisfaction

School Recommendation - Minimizing Total Dissatisfaction

There are m schools, each with an expected admission score a_i, and n students, each having an estimated score b_i. For each student, recommend a school such that the absolute difference between the student's estimated score and the school's expected score is minimized. This absolute difference is defined as the student's dissatisfaction.

The goal is to minimize the total dissatisfaction over all students. Formally, for each student i, find dissatisfactioni = min1 ≤ j ≤ m|bi - aj| and output the sum Σi=1ndissatisfactioni.

Input Format: The first line contains two integers m and n. The second line contains m integers representing the expected scores of the schools (ai). The third line contains n integers representing the estimated scores of the students (bi).

Output Format: Output a single integer, the minimum total dissatisfaction.

Note: All formulas are written in LaTeX format. For example, the dissatisfaction for a student is given by \(\min_{1 \leq j \leq m} |b_i - a_j|\).

inputFormat

The input consists of three lines:

  • The first line contains two integers \(m\) and \(n\), where \(m\) is the number of schools and \(n\) is the number of students.
  • The second line contains \(m\) integers \(a_1, a_2, \dots, a_m\) - the expected scores for each school.
  • The third line contains \(n\) integers \(b_1, b_2, \dots, b_n\) - the estimated scores for each student.

outputFormat

Output a single integer representing the minimum total dissatisfaction, which is calculated as:

\(\sum_{i=1}^n \min_{1 \leq j \leq m} |b_i - a_j|\).

sample

3 4
100 200 300
110 150 260 90
110