here is my code. I am confused with the input format that’s why I have just taken t=2 i.e 2 test case. I am using staircase algo. Please help.
#include
using namespace std;
int main() {
int t=2;
while(t>0)
{
int n;
cin>>n;
int m;
cin>>m;
int arr[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>arr[i][j];
}
}
int a;
cin>>a;
int i=0;
int j=m-1;
int flag=0;
while(i<=n-1 || j>=0)
{
if(arr[i][j]==a)
{
cout<<"1"<<endl;
flag=1;
break;
}
else if(a<arr[i][j])
j--;
else
i++;
}
if(!flag)
{
cout<<"0"<<endl;
}
t--;
}
}