Back to Cosmos

Problem Link:

code/online_challenges/src/codechef/BRKBKS/README.md

latest577 B
Original Source

Problem Link:

BRKBKS

Description

Ada's strength is SS. Whenever she hits a stack of bricks, consider the largest k≥0k≥0 such that the sum of widths of the topmost kk bricks does not exceed SS; the topmost kk bricks break and are removed from the stack. Before each hit, Ada may also decide to reverse the current stack of bricks, with no cost.

Find the minimum number of hits Ada needs in order to break all bricks if she performs the reversals optimally. You are not required to minimize the number of reversals.