Matrix Search peoblem (2nd test case is failing)

#include
using namespace std;
int main() {
int n,m,a[1000],k;
cin>>n>>m;
for(int i=0;i<nm;i++) cin>>a[i];
cin>>k;
int st=0,en=(n
m)-1,ans=0;
while(st<=en){
int mid=(st+en)/2;
if(a[mid]==k) {
ans=1;
break;
}
else if(a[mid]<k){
st=mid+1;
}
else{
en=mid-1;
}

}
cout<<ans;

return 0;

}

Provide Qn. link with your proper code.