Submission #1097285

#TimeUsernameProblemLanguageResultExecution timeMemory
1097285trinhbaongoc3006은행 (IZhO14_bank)C++17
100 / 100
86 ms8792 KiB
#include <bits/stdc++.h>
#define INF int64_t(1e9)
#define pii pair <int, int>
#define pll pair <long long, long long>
#define mp make_pair
#define file "test"
using namespace std;
const int nmax = 20;
const long long mod = 1e9 + 7;


int n, m, a[nmax + 2], notes[nmax + 2];

int dp[(1<<nmax)+10], g[(1<<nmax)+10];

void maximize(int &a, int b)
{
    if (a < b) a = b;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    //freopen(file".inp","r",stdin);
    //freopen(file".out","w",stdout);
    cin >> n >> m;
    for (int i=0;i<n;i++) cin >> a[i];
    for (int i=0;i<m;i++) cin >> notes[i];

    memset(dp,-1,sizeof dp);
    memset(g,-1,sizeof g);

    dp[0] = 0; g[0] = 0;
    for (int mask=0;mask<(1<<m);mask++)
    {
        for (int i=0;i<m;i++)
        {
            if (!(mask&(1<<i))) continue;
            int prev = mask & ~(1<<i);
            if (dp[prev] == -1) continue;
            int ok = notes[i] + g[prev];
            int need = a[dp[prev]];
            if (ok < need)
            {
                dp[mask] = dp[prev];
                g[mask] = ok;
            }
            else if (ok == need)
            {
                dp[mask] = dp[prev] + 1;
                g[mask] = 0;
            }
        }
        if (dp[mask] == n)
        {

            cout << "YES\n";
            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...