My code is not able to pass 1 test case.Can u help?

#include
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int a[n+1][m+1];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}

int key;
cin>>key;
int f=0;
for(int i=0;i<n;i++)
{
	if(a[i][m-1]<key)
	{
		continue;
	}
	else if(a[i][m-1]==key)
	{
		f=1;
		break;
	}
	else
	{
		for(int j=m-2;j>=0;j--){
			if(a[i][j]==key){
				f=1;
				break;

			}
			else if(a[i][j]<key){
				if(i!=n-1)
				i++;
				else
				break;

			}
			
		}
		if(f==1)
		break;
		
	}

}

if(f==0){
	cout<<"0"<<endl;
}
else{
	cout<<"1"<<endl;
}

}

hi @riagoel3999
refer

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.