#C11572. Maximize Mary's Stamp Collection Value
Maximize Mary's Stamp Collection Value
Maximize Mary's Stamp Collection Value
Mary loves collecting stamps and wants to maximize the total value of her collection by exchanging stamps with her friend. Initially, Mary has a collection of unique stamps with different values. She can perform a series of exchanges under the condition that she only trades one of her stamps for a friend's stamp if the friend's stamp has a strictly greater value than hers. Formally, if Mary’s stamp value is \(x\) and her friend’s stamp value is \(y\), the exchange can occur only if \(y > x\).
Determine the maximum possible total value of Mary's collection after performing a series of such exchanges.
inputFormat
The input consists of three lines:
- The first line contains two integers (n) and (m), where (n) is the number of stamps in Mary’s collection and (m) is the number of stamps in her friend’s collection.
- The second line contains (n) space-separated integers representing the values of Mary’s stamps.
- The third line contains (m) space-separated integers representing the values of her friend’s stamps.
outputFormat
Output a single integer representing the maximum possible total value of Mary’s stamp collection after the exchanges.## sample
3 3
4 5 8
3 7 9
24