Submission #1124852

#TimeUsernameProblemLanguageResultExecution timeMemory
1124852njoopBank (IZhO14_bank)C++17
0 / 100
3 ms4424 KiB
#include <bits/stdc++.h>

using namespace std;

int cov[2000010], mon[2000010], notes[30], ppl[30], n, m;

int main() {
    cin >> n >> m;
    for(int i=0; i<n; i++) {
        cin >> ppl[i];
    }
    for(int i=0; i<m; i++) {
        cin >> notes[i];
    }
    for(int i=0; i<=(1<<20); i++) {
        cov[i] = -1;
    }
    cov[0] = 0;
    for(int i=0; i<(1<<m); i++) {
        for(int j=0; j<m; j++) {
            if(i & (1 << j) == 0) continue;
            int pre = i & ~(1 << j);
            if(cov[pre] == -1) continue;
            if(mon[pre]+notes[j] < ppl[cov[pre]]) {
                if(cov[i] <= cov[pre]) {
                    cov[i] = cov[pre];
                    mon[i] = mon[pre]+notes[j];
                }
            } else if(mon[pre]+notes[j] == ppl[cov[pre]]) {
                if(cov[i] <= cov[pre]+1) { 
                    cov[i] = cov[pre]+1;
                    mon[i] = 0;
                }
            }
        }
        if(cov[i] == n) {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...