Hey, please check the code, test cases 1 and 2 are not being passed.
#include
using namespace std;
//s = initial eergy
//k = threshold energy
void magical_park(char park[][100], int m, int n, int k, int s){
bool success = true;
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
char ch = park[i][j];
if(s<k){
success = false;
break;
}
else if(ch == '*')
s += 5;
else if(ch == '.')
s -= 2;
else
break;
if(j < n-1)
s--;
}
}
if(success){
cout<<"Yes"<<endl;
cout<<s;
}
else
cout<<"no";
}
int main(){
int n,m,k,s;
cin>>n>>m>>k>>s;
char park[100][100];
for(int i=0; i<m; i++){
for(int j=0 ; j<n; j++){
cin>>park[i][j];
}
}
magical_park(park,m,n,k,s);
return 0;
}