fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int a[10],b[10],i,j,n,k,x,v;
  6. cin>>n,k;
  7. for (i=0; i<n;i++)
  8. cin>>a[i];
  9. for (i=0;i<k;i++)
  10. cin>>b[i];
  11. for (i=0;i<n-1;i++)
  12. for (x=n-2;x>=i;x--)
  13. if (a[i]>a[i+1])
  14. {
  15. j=a[i+1];
  16. a[i+1]=a[i];
  17. a[i]=j;
  18. }
  19. i=n;
  20. for (x=0;x<k;x++)
  21. { v=0;n=i;
  22. while (v<n-1)
  23. {
  24. j=(v+n)/2;
  25. if (b[x]<a[j])
  26. n=j;
  27. else v=j;
  28. }
  29. if (b[x]==a[j])
  30. cout<<"YES"<<endl;
  31. else
  32. cout<<"NO"<<endl;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 3468KB
stdin
10 5
1 2 3 4 5 6 7 8 9 10 
-2 0 4 9 12 
stdout
Standard output is empty