Piyush and magical park problem - i tried out this problem but my code is giving incorrect output. For the sample example, its printing strength as 8 instead of 13. Can you please check and tell where did i went wrong. TIA

Here is my code -
#include #include using namespace std; int main() { int m,n,k,s; cin>>m>>n>>k>>s; string a[m][n]; //input cin.get(); for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ getline(cin,a[i][j]); } } for(int i=0;i<m;i++){ int j = 0; if(s<k){ break; } //obstacle . else if(a[i][j]=="." && s>=k){ s -= 2; } //magic * else if(a[i][j]=="" && s>=k){ s += 5; } //blockage # else if(a[i][j]=="#"){ break; } for(j=1;j<n;j++){ s -= 1; if(s<k){ break; } //obstacle . else if(a[i][j]=="." && s>=k){ s -= 2; } //magic * else if(a[i][j]=="" && s>=k){ s += 5; } //blockage # else if(a[i][j]=="#" && s>=k){ break; } } } if(s>=k){ cout<<β€œYes”<<endl<<s; } else{ cout<<β€œNo”; } return 0; }

break when s<k ,dont return