July Challenge Question: Bread. Need help clearing a doubt.

If a packet is opened and has bread left in it, it’s content will be -1.

Now if, the 2nd day, we decide not to eat from the packet, does the content again be subtracted by -1?

For example: What is the answer for the test case:

4 5

3 3 1 1

Thank you!

@thespacedude:

Why wont we decide to eat if the bread pieces are good? So,defenetly they will decide to eat the all good pieces of bread available with them.

For the above example, the answer is 3 … i.e… 3 bread packets are needed to be carried with them to the tour.

Let us say that Count is desired output i.e … the number of bread packets needed

On the 1st day they want to eat 3 bread pieces and since each packet contains 5 pieces,they eat 3 pieces and 2 pieces will be left out of which 1 will be rotten and 1 will be good.(Count = 1)

On the 2nd day. they want to 3 pieces again, as in the previous bread packet there is 1 good bread piece they will eat that and still they need 2 for which they will open another new packet and take 2 pieces in that and finally 3 will be remaining in the second bread packet out of which one will be rotten and 2 will be good.(Count = 2)

On the 3rd day, they want to eat 1 bread piece. As we have 2 good bread pieces in the last packet, they will eat one from that and 1 piece is still left in the packet which will be rotten. (Count = 2)

On the 4th day, they want to eat 1 bread piece, As we have no left pieces from the previous packets, we will open a new bread packet and eat 1 from that (Count = 3).

SO, FINALLY THEY HAVE TO CARRY 3 BREAD PACKETS WITH THEM FOR THEIR TOUR!

3 Likes

According to the rules, we are not allowed to discuss questions and doubts related to the ongoing contest.
Codechef, please look into the matter.

2 Likes

Funny thing is that I have just been doing the opposite of method explained here and I have got over 20 WAs for this simple problem and I have no idea why.

simple implementation…