Problem C
Room Painting
Joe’s landlord has allowed him to paint his room any colour
that he wants, even multiple colours. Joe has come up with a
very colourful design. Now he needs to buy the paint. Being a
struggling student, Joe does not want to waste any money, so he
has calculated the exact amount that he needs of each colour
down to the microlitre. To his surprise, however, the local
paint shop is unwilling to sell him a can of exactly
Joe has no choice but to buy a little bit more paint than he really needs. Still, he would like to minimize the amount of paint wasted. In addition, he does not want to buy more than one can of any given colour.
Input
The first line of input contains two integers
Each of the next
Each of the next
Output
Output a single line, the total number of microlitres of paint wasted if Joe buys, for each colour, the smallest can that satisfies his needs.
Sample Input 1 | Sample Output 1 |
---|---|
3 2 5 7 9 6 8 |
2 |