Problem B
Money Matters
Our sad tale begins with a tight clique of friends. Together
they went on a trip to the picturesque country of Molvania.
During their stay, various events which are too horrible to
mention occurred. The net result was that the last evening of
the trip ended with a momentous exchange of “I never want to
see you again!”s. A quick calculation tells you it may have
been said almost
Back home in Scandinavia, our group of ex-friends realize that they haven’t split the costs incurred during the trip evenly. Some people may be out several thousand crowns. Settling the debts turns out to be a bit more problematic than it ought to be, as many in the group no longer wish to speak to one another, and even less to give each other money.
Naturally, you want to help out, so you ask each person to tell you how much money she owes or is owed, and whom she is still friends with. Given this information, you’re sure you can figure out if it’s possible for everyone to get even, and with money only being given between persons who are still friends.
Input
The first line contains two integers,
After this comes
Output
Your output should consist of a single line saying “POSSIBLE” or “IMPOSSIBLE”.
Sample Input 1 | Sample Output 1 |
---|---|
5 3 100 -75 -25 -42 42 0 1 1 2 3 4 |
POSSIBLE |
Sample Input 2 | Sample Output 2 |
---|---|
4 2 15 20 -10 -25 0 2 1 3 |
IMPOSSIBLE |