Submission #648404

#TimeUsernameProblemLanguageResultExecution timeMemory
648404MEGalodonBank (IZhO14_bank)C++14
19 / 100
78 ms8404 KiB
#include <bits/stdc++.h>
#define MAXN 20
using namespace std;
int dp[(1<<MAXN)], leftover[(1<<MAXN)];
int salary[MAXN], bnkNotes[MAXN];
int main(){
    int N, M;
    cin>>N>>M;
    for( int i{0} ; i < N ; ++i ) cin>>salary[i];
    for( int i{0} ; i < M ; ++i ) cin>>bnkNotes[i];
    memset(dp, -1, sizeof(dp));
    dp[0] = 0; leftover[0] = 0;
    for( int S{1} ; S < (1<<M) ; ++S ){
        for( int i{0} ; i < M ; ++i ){
            if( S&(1<<i) ){
                int prev = S^(1<<i);
                if( dp[prev] == -1 ) continue;
                int t = salary[dp[prev]];
                int cur = leftover[prev]+bnkNotes[i];
                if( cur < t ){
                    dp[S] = dp[prev];
                    leftover[S] = cur;
                }
                else if( cur == t ){
                    dp[S] = dp[prev]+1;
                    leftover[S] = 0;
                }
                break;
            }
        }
        if( dp[S] == N ){
            cout<<"YES\n";
            return 0;
        }
        //cout<<dp[S]<<" "<<leftover[S]<<" "<<S<<'\n';
    }
    cout<<"NO\n";
    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...