Submission #870878

#TimeUsernameProblemLanguageResultExecution timeMemory
870878sleepntsheepBank (IZhO14_bank)C++17
0 / 100
18 ms17104 KiB
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using i64 = long long;

int z=4, n, m, a[21], b[20], dp[2][1<<20];

int main()
{
    ShinLena;
    cin >> n >> m;
    memset(dp, 0x86, sizeof dp);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 0; i < m; ++i) cin >> b[i];
    dp[0][0] = 0;
    for (int i = 0, I = 0; i <= n; ++i, I^=1)
    {
        if (i) memset(dp[I], 0x86, sizeof *dp);
        for (int j = 0; j < (1 << m); ++j)
        {
            if (i)
                if (dp[!I][j] == a[i]) dp[I][j] = 0;
            for (int k = 0; k < j; ++k)
            {
                if (j & (1 << k))
                {
                    int p = j&~(1<<k);
                    dp[I][j] = max(dp[I][j], dp[I][p] + b[k]);
                }
            }

            if (i == n && !dp[I][j]) z = 0;
        }
    }
    cout << &"YES\0NO"[z];
    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...