Getting wrong answer

Hello …
I am doing this question from hackerearth…

I have solved this question with following logic…
1)… I have stored the sweetness and price of soft chocklate…
2)… Now i have iterating over each sweetness of choclate.
3)… If my power is not used then… If the current sweetness/2 is greater than my remaining sweetness then i will go to next index.
If the current sweetness/2 is less than the remainin sweetness but current sweetness is greater than the remaining sweetness so we have only two option either use power or not and calculate maximum in that.

Now if current sweetness/2 is less than the remaining sweetness then i have 3 possibilities … i have calculated maximum in that…

4)… If power is used then also i have considered that case… Here “F” indicates power is used or not…

Here is my solution…
https://www.hackerearth.com/submission/51564270/

Please see this…
Thanks…

Hello @ashishnnnnn wait let me see your logic and code:
i think you should see the discussion as well for the questions in which you have doubt.

@ashishnnnnn you can see this code for your reference :


tell me if this helps you.
Happy Learning!!

Hii…
I am not much confident in bottom up approch…
I think my code is correct… It is having just some mistake…
If possible see it…

Hello i am asking you to go through this code and try to crack the logic so that it can help you.
because bottom up approach is good for understanding.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.