#K61567. Minimize Wasted Space

    ID: 31338 Type: Default 1000ms 256MiB

Minimize Wasted Space

Minimize Wasted Space

You are given n storage units and m items. Each storage unit has a certain capacity and each item requires a certain amount of space. Your task is to assign each item to a unique storage unit such that the storage unit's capacity is not less than the item's size. The wasted space when an item of size \( S \) is placed into a storage unit of capacity \( C \) is defined as \( C - S \). The goal is to minimize the total wasted space over all assignments.

If it is impossible to store all the items (i.e. \( n < m \) or no storage unit can accommodate a particular item), output \(-1\).

inputFormat

The first line contains two integers, \( n \) and \( m \), where \( n \) is the number of storage units and \( m \) is the number of items.

The second line contains \( n \) integers representing the capacities of the storage units. If \( n = 0 \), this line will be empty.

The third line contains \( m \) integers representing the sizes of the items. If \( m = 0 \), this line will be empty.

outputFormat

Output a single integer: the minimum total wasted space if all items can be stored; otherwise, output \(-1\).

## sample
5 3
10 15 8 6 20
5 12 7
5

</p>