#C1884. Maximize Book Savings
Maximize Book Savings
Maximize Book Savings
Emma wants to maximize her savings while purchasing books using vouchers. She has a list of book prices and a list of vouchers, each representing a discount value. A voucher can only be used if the corresponding book's price is at least as much as the voucher's discount value, and each voucher can be applied to only one book.
The problem can be formulated as follows: Given two integers \(n\) and \(m\) representing the number of books and vouchers respectively, along with two arrays of integers for the book prices and voucher discounts, determine the maximum total savings that Emma can obtain by using the vouchers optimally.
inputFormat
The input is given via standard input (stdin) and consists of three lines:
- The first line contains two integers \(n\) and \(m\) separated by a space, where \(n\) is the number of books and \(m\) is the number of vouchers.
- The second line contains \(n\) integers representing the prices of the books.
- The third line contains \(m\) integers representing the discount values of the vouchers.
outputFormat
Output a single integer to standard output (stdout): the maximum total savings that can be achieved by applying the vouchers to the books, following the condition that a voucher can be used only if the book's price is greater than or equal to the voucher's value.
## sample5 3
50 30 20 10 40
10 20 30
60