#P10771. Maximizing Contest Team Strength

    ID: 12809 Type: Default 1000ms 256MiB

Maximizing Contest Team Strength

Maximizing Contest Team Strength

You are a teacher with \(n\) students. Each student has a physics score \(A_i\) and a biology score \(B_i\). You are required to assign each student to exactly one contest. Exactly \(a\) students must participate in the physics contest and exactly \(b\) students must participate in the biology contest. Note that since every student participates in exactly one contest, it is guaranteed that \(a + b = n\).

The strength of your school is defined as the sum of the physics scores of the students selected for the physics contest plus the sum of the biology scores of the students selected for the biology contest. Your task is to find the maximum possible strength.

Hint: You can think of it as initially assigning every student to the biology contest, and then choosing \(a\) students to switch to the physics contest. The additional gain for switching student \(i\) is \(A_i - B_i\). Therefore, the optimal solution is to choose the \(a\) students with the largest values of \(A_i - B_i\).

inputFormat

The first line contains three integers \(n\), \(a\), and \(b\) (with \(a + b = n\)). The second line contains \(n\) integers representing the physics scores \(A_1, A_2, \dots, A_n\). The third line contains \(n\) integers representing the biology scores \(B_1, B_2, \dots, B_n\).

outputFormat

Output a single integer representing the maximum possible strength of the school.

sample

5 3 2
5 4 7 3 9
1 2 3 4 5
27