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…