Piyush and magical park max energy

unable to find maximum energy . plzz check my code
https://ide.codingblocks.com/s/75553

Hi himanshu,
See if there is ‘.’ the your energy should decrease by 2 not by 3 also if there is ‘*’ then your energy should increase by 5 not by 4 also if column is not equal to last one you have to decrease the energy by 1 after each move. Also you have to maintain one flag variable initially initialize with true, if in a column energy is less than k then reinitialize flag with false and break. Outside both loop check if flag is true or false. If true then print yes and energy else print no.

But question says itself that for each move in travelling through row our energy gets decreased by 1 so when i encounter a ‘.’ my energy decreased by -2-1=-3 and when i encounter a ‘*’ my energy decreased by +5-1=4.

Hi Himanshu,
You are right but consider there are four column and in first row there are ‘.’ in each column then acc to question your energy must decrease by 11 i.e. resultant energy after traversing 1st row should be s - 11 but according to your code it will get decrease by 12 i.e. resultant will be s - 12 which is wrong.

ya i got ur logic and i have done changes in my code even then i am not been able to print the max energy. plzz look at the code https://ide.codingblocks.com/s/75705

Hi Himanshu,
As i earlier mentioned if the column is not last one you have to decrease the energy by 1. I have corrected this and you can see this in below link:

thank u sanyam now i have got my mistake.