제출 #723399

#제출 시각아이디문제언어결과실행 시간메모리
723399quochuy147Bank (IZhO14_bank)C++14
100 / 100
108 ms8532 KiB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define file "bank" 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;}

const int mod = 1e9 + 7;
const int N = 20;

int n, m;
int a[N + 5], b[N + 5];
pii f[MASK(N) + 5];

void inp()
{
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= m; ++i) cin >> b[i];    
}

void solve()
{
    for(int i = 1; i < MASK(m); ++i) f[i].fi = -1;
    f[0] = {1, 0};
    for(int i = 1; i < MASK(m); ++i)
        for(int j = 1; j <= m; ++j) {
            if(MASK(j - 1) & i) {
                int pre = MASK(j - 1) ^ i;
                if(f[pre].fi == -1) continue;
                int cnt = f[pre].fi, val = f[pre].se;
                if(val + b[j] < a[cnt]) f[i] = {f[pre].fi, val + b[j]};
                if(val + b[j] == a[cnt]) f[i] = {f[pre].fi + 1, 0};
                if(f[i].fi > n) {
                    cout << "YES";
                    return ;
                }
            }
        }
    cout << "NO";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // freopen(file".in" , "r" , stdin);
    // freopen(file".out" , "w" , stdout);
    inp();
    solve();
    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...