Official algorithmic problem description and constraints.
Being a physicist, Charlie likes to plan his life in simple and precise terms.
For the next π months, starting with no money, Charlie will work hard and earn π₯ pounds per month. For the π-th month (1β€πβ€π), there'll be a single opportunity of paying cost ππ pounds to obtain happiness βπ.
Borrowing is not allowed. Money earned in the π-th month can only be spent in a later π-th month (π>π).
Since physicists don't code, help Charlie find the maximum obtainable sum of happiness.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.