Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool matrix_src(int n,int m,int a[500][500],int x)
- {
- int i=0,j=n-1;
- while (i<n&&j>=0)
- {
- if (x==a[i][j])
- return true;
- else if (x<a[i][j])
- j--;
- else
- i++;
- }
- return false;
- }
- int main()
- {
- int a[500][500],n,m,i,j,k,v[5000];
- cin>>n>>m;
- for (i=0; i<n; i++)
- for (j=0; j<m; j++)
- cin>>a[i][j];
- cin>>k;
- for (i=0; i<k; i++)
- cin>>v[i];
- for (i=0; i<k; i++)
- {
- if (matrix_src(n,m,a,v[i]))
- cout<<"DA"<<'\n';
- else
- cout<<"NU"<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement