Why my only 3 test case is passing out of 5

#include<bits/stdc++.h>
using namespace std;
int main() {
int n,m,k,s;
cin>>n>>m>>k>>s;
string a[n][m];
int f=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>a[i][j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j]==".")
s=s-2;
if(a[i][j]=="*")
s=s+4;
if(a[i][j]=="#")
break;
if(s<=k)
{
f=1;
break;
}

	}
}
if(f==0)
cout<<"Yes"<<endl<<s;
else
cout<<"No";

return 0;

}

Hi @ayushwahi3005
When piyush encounter ‘.’ then his strength will decrease by 3 if he is not in the last column because 2 energy is wasted by ‘.’ and 1 is because of each step, and also if he encounters ’ * ’ in the last column then his energy will increment by 5. So after correcting these cases your code will be as follows :

If your doubt is clear then mark it as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.