#P2813. Mother Ship Battle Damage Calculation

    ID: 16074 Type: Default 1000ms 256MiB

Mother Ship Battle Damage Calculation

Mother Ship Battle Damage Calculation

In the interstellar war game of Little A, the power of the mothership plays a decisive role. A mothership is equipped with several attack systems and several defense systems. During a duel, a mothership can choose one of its attack systems to target one of the enemy's defense systems. If the chosen attack system's attack value is strictly greater than the defense system's defense value, then that defense system is destroyed. Once all enemy defense systems are destroyed, any remaining attack systems will directly inflict damage to the enemy mothership equal to their attack value.

Your task is to compute the maximum damage your mothership can inflict on the enemy mothership. Formally, let your mothership have an array A of attack values and the enemy mothership have an array D of defense values. You must select a subset of your attack systems to destroy enemy defenses such that for every defense d in D, you assign an attack system with value a satisfying \[ a > d \] If it is impossible to destroy all enemy defense systems with your available attack systems, the damage is 0. Otherwise, if S is the sum of the attack values used in destroying enemy defenses and T is the total attack value of all systems, then the damage inflicted to the enemy mothership is \[ Damage = T - S \] Determine the maximum damage achievable by optimally selecting which attack systems are used for defense removal (i.e. using the smallest possible attack that succeeds for each enemy defense) so that the leftover attack systems yield maximal direct damage.

inputFormat

The first line contains two integers N and M, representing the number of attack systems and the number of enemy defense systems respectively.

The second line contains N space-separated integers, the attack values of your mothership's systems.

The third line contains M space-separated integers, the defense values of the enemy mothership's systems.

outputFormat

Output a single integer representing the maximum damage your mothership can inflict on the enemy mothership. If it is impossible to destroy all enemy defense systems, output 0.

sample

3 2
3 5 7
2 6
5