Submission #1026995

#TimeUsernameProblemLanguageResultExecution timeMemory
1026995kkkkkkkk은행 (IZhO14_bank)C++14
100 / 100
88 ms8656 KiB
#include <bits/stdc++.h>

using namespace std;

pair<int, int> dp[1<<21];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    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];
    dp[0]={0, 0};
    for (int state=0;state<(1<<m);state++) {
        if (dp[state].first==n) {
            cout << "YES";
            return 0;
        }
        for (int i=0;i<m;i++) {
            if (state&(1<<i)) continue;
            pair<int,int> new_state;
            if (dp[state].second+b[i]==a[dp[state].first])
                new_state={dp[state].first+1, 0};
            else
                new_state={dp[state].first, dp[state].second+b[i]};
            dp[state|(1<<i)]=max(dp[state|(1<<i)], new_state);
        }
    }
    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...