Manage Your Energy

Did problem B of round 1B of code jam 2013: Manage Your Energy.

Only works for small test case.