Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int n, q;
- cin >> n >> q;
- vector<int> a(n);
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- sort(a.begin(), a.end());
- for (int i = 0; i < q; ++i) {
- int x;
- cin >> x;
- int buf = x;
- long long sum = 0;
- while (x != 0) {
- int y = upper_bound(a.begin(), a.end(), x) - a.begin() - 1;
- if (y >= 0) {
- x = x % a[y];
- sum += a[y];
- }
- else {
- break;
- }
- }
- if (sum == buf) {
- cout << "Yes\n";
- }
- else {
- cout << "No\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement