Algorithm of 11150 - Cola

Problem Description Link
Algorithm:
This is a very simple problem just you need to read carefully .
The main condition for this problem is " A bottle of Choco Cola for every 3 empty bottles returned ".
Now you decide to buy some (say N) bottles of cola from the store. You would like to know how you can get the most cola from them.
However you can follow this method to solve this problem.


best way to get maximum cola you buy two(2) cola and brow a (1) empty cola
so you get one (1) cola and return to donor.
so you can get maximum cola.
For example:
 Let you have 8 cola
so get 2 cola and borrow 1 cola so you have (2+1=3) empty cola so you get 1 bonus and return to donor
 so you enjoy =3 and in your hand=8-2=6
again (2+1=3)
so you enjoy =3+3 and in your hand=6-2=4
again (2+1=3)
so you enjoy =3+3+3 and in your hand=4-2=2
again (2+1=3)
so you enjoy =3+3+3+3 and in your hand=2-2=0
So total enjoy =12 cola
image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience