Emiliatan

b542

Feb 23rd, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. /* b542             */
  2. /* AC (0.2s, 480KB) */
  3. #include <cstdio>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. typedef unsigned int uint;
  9.  
  10. const int MAXN = 100001;
  11. uint N, Q, K, p, q, arr[MAXN];
  12.  
  13. int main()
  14. {
  15.     scanf("%u %u", &N, &Q);
  16.     for(uint i = 0; i < N && scanf("%u", &arr[i]); i++);
  17.     sort(arr, arr + N);
  18.     for(uint i = 0; i < Q && scanf("%u", &K); i++)
  19.     {
  20.         p = 0, q = 1;
  21.         while(arr[q] - arr[p] != K && q < N && p < N)
  22.             if(arr[q] - arr[p] > K) p++;
  23.             else q++;
  24.         if(arr[q] - arr[p] == K) puts("YES");
  25.         else puts("NO");
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment