// Johnny Boldt // Feb 27, 2011 // johnny.boldt@gmail.com Note: This is the same problem as 11877 The solution to this problem is quite trivial, one only has to convince himself that it will work. Essentially, one uses a "greedy algorithm." 1) The person drinks all the bottles possible. Then each group of 3 empties yields a new full bottle. Repeat. 2) If the person has a leftover group of two bottles, he benefits one more bottle, since he can borrow one, drink all 3 and then pay it back with the new empty bottle gained from this group 3) If the person has a leftover group of one bottle, he just throws it away. Borrowing two bottles will result in the person being unable to pay the friend back. I am actually using Method 1! The difference is, at the end I borrow a bottle, not at the start. The pictures are misleading, since in Method 1, it can be: 0=empty @ = full @@@@@@@@ 8 @@00 2 @00 1 (Note, bottle borrowed here) @ 1 In fact, it doesn't matter when the bottle is borrowed, just as long as it is borrowed at some point.