Piyush and Magic Park

I have written the code for this problem but 2 of the test cases are not passing. Please point out where am I going wrong. Here is the link to my code:-


Problem Link:-https://hack.codingblocks.com/app/contests/1872/1051/problem

Hello @arunimakhanna11

in problem u r given NX M matrix but u are taking M xN
check ur corrected code->

#include<iostream>
using namespace std;
void magicPark(char arr[][100],int M, int N, int K, int S){
	bool success = true;
	for(int i=0;i<N;i++){    // interchanged N and M 
		for(int j=0;j<M;j++){
			char ch = arr[i][j];
			if(S<K){
				success = false;
				cout<<"No";
				return;
			}
			if(ch=='.'){
				S-=2;
			}
			else if(ch=='*'){
				S+=5;
			}
			else{
				break;
			}
			if(j!=N-1)
				S--;
		}
	}
	if(success){
		cout<<"Yes"<<endl<<S;
	}
	else{
		cout<<"No";
	}
}
int main() {
	int N,M,K,S;
	cin>>N>>M>>K>>S;
	char arr[100][100];
	for(int i=0;i<N;i++){    // interchanged N and M 
		for(int j=0;j<M;j++){
			cin>>arr[i][j];
		}
	}
	magicPark(arr,M,N,K,S);
	return 0;
}
1 Like