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?
The first line of the input file contains an integer T, which is the number of test cases.
The first line of each test case is N, the number of people at the table. This is followed by N lines, one for each i in [1,N], containing
You may assume that no person owes more money than they have 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.
For each test case, output "YES" if all of the money can be rearranged
so that each person ends up paying the correct amount and "NO" if not.
3 1 10 0 0 1 0 0 0 0 0 0 0 2 0 0 0 0 0 2 0 0 0 0 0 500 0 0 0 0 0 1 0 0 0 0 1 100 4 0 2 3 0 1 0 0 0 0
YES YES NO
Migrated from old NTUJ.
MIT Individual 2008
No. | Testdata Range | Score |
---|