This is a question of MISSION CODE day 1.

I’m not getting what m denotes in this question also it is not mentioned in question.

So, the creators of contest plss tell so that I can give a try to that question.

one compartment has m green blocks each of unit height

I am really confused about this problem, as it seems quite simple but the following solution gets a WA:

Let the current height be A, next height be B. Then there are only 3 possibilities:

- A=B → then there is only one thing we can do, to proceed without changes.
- A>B → then there is only one action: to replace the current sack contents with A-B and proceed.
- A<B → there are two cases, depending on the size of the current sack contents, lets denote them C:

3.1 A+C<B → there are two actions we can take: either use up B-A-C green blocks, empty the sack and proceed, or use B-A green blocks and leave C unchanged.

3.2 A+C>B → there are two actions: either we use B-A green blocks and leave C unchanged, or we replace C with C-(B-A) and proceed.

But since we can use red blocks in place of green blocks, but not vice versa, it is always better to use more red blocks than green blocks. Therefore, there are only one action we can take in each case.

Could you please tell where the above logic is wrong?

I applied the following logic:

Let’s say we have array = [5,6,3,4,7] and 2 green blocks

Now, calculate the difference in the burst of 2

i.e new array = [1,-3,1,3]

Now according to the new array -VE values represents red blocks in sack

So in total we have available = 2(Green)+3(Red)=5 blocks in total

And we require required = 1+1+3=5 blocks to reach the end

Since here required==available we can reach the end;

Hope you understood this

Here’s link to my solution for reference!!!

no. of green blocks of unit height!!

What about the case like [20,10,5,20] which leads to a difference array of [-10,-5,15], which would imply we have 15 red blocks and we need 15 red blocks to pass. But since we can only hold one red block at a time, we can only hold 5 red blocks, not all 15 at a time, meaning we would need extra 10 green blocks to pass.