Piyush and magical park wrong output

wrong output

You are using a somewhere wrong approach in your solution, You have to use these conditions for getting the correct answer,

  1. if(S<K)
    {
    break;
    }
  2.  if(ar[i][j]=='.')
     {
       S=S-2;
       S--;
     }
    
  3.  if(ar[i][j]=='*')
     {
       S=S+5;
       S--;
     }
    
  4.  if(ar[i][j]=='#')
     {
       N=N+1;
     }
    
  5.  if(ar[i][j]=='#' && i==N-1)
     {
       break;
     }
    

Plz use these conditions only.