Not passing all the test cases

@Ankur752
import java.util.*;
public class Main {
public static void main(String args[]) {
// System.out.println(“Hello World!”);
Scanner sc=new Scanner(System.in);

	int n=sc.nextInt();
	int m=sc.nextInt();

	int k=sc.nextInt();
	int s=sc.nextInt();
	char arr[][]=new char[n][m];
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			arr[i][j]=sc.next().charAt(0);
		}
	}

int c=	Magic(arr,s,k);
//System.out.println();
if(c>k)
{
	System.out.println("Yes");
	System.out.println(c);
}
else
System.out.println("No");

}
public static int Magic(char[][] arr,int count ,int k)
{

	for(int i=0;i<arr.length;i++)
	{
		for(int j1=0;j1< arr[0].length;j1++)
		{
			char ch = arr[i][j1];
			if(count<k){
				return -1;
			}
			if(arr[i][j1]=='.')
				{count=count-2;}
			else if(arr[i][j1]=='*')
			{count=count+5;}
			else //if(arr[i][j1]=="#")
			{break;}
				
			 if (j1 != arr[0].length - 1)
                    count--;
			
		}
	}
	return count;
}

}

there might be the case where value of count become less than k in between so you need to check that edge case as well.