Advertisement
MegaVerkruzo

Untitled

Sep 16th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int n, q;
  10. cin >> n >> q;
  11. vector<int> a(n);
  12. for (int i = 0; i < n; ++i) {
  13. cin >> a[i];
  14. }
  15. sort(a.begin(), a.end());
  16. for (int i = 0; i < q; ++i) {
  17. int x;
  18. cin >> x;
  19. int buf = x;
  20. long long sum = 0;
  21. while (x != 0) {
  22. int y = upper_bound(a.begin(), a.end(), x) - a.begin() - 1;
  23. if (y >= 0) {
  24. x = x % a[y];
  25. sum += a[y];
  26. }
  27. else {
  28. break;
  29. }
  30. }
  31. if (sum == buf) {
  32. cout << "Yes\n";
  33. }
  34. else {
  35. cout << "No\n";
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement