Piyush And Magical Park Problem

i wrote this code for the problem.
it shows time limit exceeded.
is there a better solution in c++.
please tell

using namespace std;

int main() {

int n,m,s,k;
cin>>n>>m>>k>>s;

char a[n][m];

for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];

bool success = true;

for(int i=0;i<m;i++)
{
	for(int j=0;j<n;j++)
	{
		char ch = a[i][j];
		if(s<k)
		{
			success = false;
			break;
		}
		if(ch=='*')
		{
			s+=5;
		}
		else if(ch=='.')
		{
			s-=2;
		}
		else{
			break;
		}
		if(j!=n-1)
		{
			s--;
		}
	}
}
if(success)
{
	cout<<"Yes"<<endl;
	cout<<s<<endl;
}
else
{
	cout<<"No"<<endl;
}

return 0;

}