SP3582 RSTAURNT - Restaurant Tab
Description
After eating dinner at a restaurant with some friends, you determine how much money each person owes. Each of you has some cash and some change, but very few of you have exact change. Can you make change for each other so that each person ends up paying the exact right amount?
Input Format
The input file will contain multiple cases. The first line of each case is N, the number of people at the table. This is followed by N lines, one for each i ∈ \[1,N\], containing
x $ _{i} $ c $ _{i,1} $ c $ _{i,5} $ c $ _{i,10} $ c $ _{i,25} $ c $ _{i,100} $ c $ _{i,500} $ c $ _{i,1000} $ c $ _{i,2000} $ c $ _{i,5000} $ c $ _{i,10000} $ where x $ _{i} $ is the amount in cents that person i owes and c $ _{i,v} $ is the number of coins or bills worth v cents that person i starts out with. For example, person 1 has c $ _{1,1} $ pennies, c $ _{1,5} $ nickels, etc. Each case is followed immediately by the next case. The end of the input is indicated by a line containing only a zero. You may assume that no person owes more money than they have (i.e. x $ _{i} $ ≤ Σ $ _{j} $ j\*c $ _{i,j} $ ) and that the total amount of money in cents that everyone starts with fits in a signed 32-bit integer. You may also assume that N ≤ 100000.
Output Format
For each case, output the case number, in the format "Case #:" (where # is the case number, starting at 1), followed by a space, followed by "YES" if all of the money can be rearranged so that each person ends up paying the correct amount and "NO" if not.