Submission #778025

#TimeUsernameProblemLanguageResultExecution timeMemory
778025vgoofficialBank (IZhO14_bank)C++14
100 / 100
106 ms8520 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    int salary[n], notes[m];
    for(int i = 0; i < n; i++) cin >> salary[i];
    for(int i = 0; i < m; i++) cin >> notes[i];
    int peoplePaid[1<<m];
    int lastPerson[1<<m];
    peoplePaid[0]=0;
    lastPerson[0]=0;
    for(int i = 1; i < 1<<m; i++) {
        peoplePaid[i]=-1;
        for(int j = 0; j < m; j++) {
            if(i&(1<<j)) {
                if(peoplePaid[i^(1<<j)]==-1) continue;
                int ppl = peoplePaid[i^(1<<j)];
                if(lastPerson[i^(1<<j)]+notes[j]==salary[ppl]) {
                    peoplePaid[i]=ppl+1;
                    lastPerson[i]=0;
                    if(ppl+1==n) {
                        //cout << i << endl;
                        cout << "YES" << endl;
                        return 0;
                    }
                } else if(lastPerson[i^(1<<j)]+notes[j]<salary[ppl]) {
                    peoplePaid[i]=peoplePaid[i^(1<<j)];
                    lastPerson[i]=lastPerson[i^(1<<j)]+notes[j];
                } 
            }
        }
    }
    cout << "NO" << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...