Last active
May 15, 2018 09:36
-
-
Save mishal23/f2682b37f1ef3eb9daf027419cd19275 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "bits/stdc++.h" | |
using namespace std; | |
int main() | |
{ | |
int t; | |
cin>>t; | |
while(t--) | |
{ | |
int n,m,x,i,j; | |
cin>>n>>m; | |
int a[n][m]; | |
for(i=0;i<n;i++) | |
{ | |
for(j=0;j<m;j++) | |
{ | |
cin>>a[i][j]; | |
} | |
} | |
cin>>x; | |
i=0; | |
j=m-1; | |
bool done=false; | |
while(i<n && j>=0) | |
{ | |
if(a[i][j]==x) | |
{ | |
done=true; | |
cout<<"1"<<endl; | |
break; | |
} | |
else if(a[i][j]<x) | |
{ | |
i++; | |
j=m-1; | |
} | |
else | |
{ | |
j--; | |
} | |
} | |
if(!done) | |
{ | |
cout<<"0"<<endl; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment