Submission #1255838

#TimeUsernameProblemLanguageResultExecution timeMemory
1255838inkvizytorBank (IZhO14_bank)C++20
100 / 100
67 ms9544 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a (n), b (m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    vector<pair<int, int>> t (1<<m);
    vector<bool> odw (1<<m, 0);
    t[0] = {0, 0};
    odw[0] = 1;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        if (t[x].first == n) {
            cout << "YES\n";
            return 0;
        }
        for (int i = 0; i < m; i++) {
            if (odw[x|(1<<i)]) {
                continue;
            }
            if (t[x].second+b[i] > a[t[x].first]) {
                continue;
            }
            else if (t[x].second+b[i] == a[t[x].first]) {
                t[x|(1<<i)] = {t[x].first+1, 0};
                odw[x|(1<<i)] = 1;
                q.push(x|(1<<i));
            }
            else {
                t[x|(1<<i)] = {t[x].first, t[x].second+b[i]};
                odw[x|(1<<i)] = 1;
                q.push(x|(1<<i));
            }
        }
    }
    cout << "NO\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...