Posts

Showing posts from January, 2020

CodeChef : Breaking Bricks || Problem Code: BRKBKS

CodeChef : https://www.codechef.com/JAN20B/problems/BRKBKS Problem: For her next karate demonstration, Ada will break some bricks. Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are W1,W2,W3. Ada's strength is S. Whenever she hits a stack of bricks, consider the largest k≥0 such that the sum of widths of the topmost k bricks does not exceed S; the topmost k 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 minimise the number of reversals. Input The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first and only line of each test case contains four space-separated integers S, W1, W2 and W3. Output For each test case, pri