제출 #886972

#제출 시각아이디문제언어결과실행 시간메모리
886972Amirreza_FakhriBank (IZhO14_bank)C++17
19 / 100
82 ms8648 KiB
// In the name oF the God 
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
using namespace std;

const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 20;

int n, m, a[1000], b[1000];
pii dp[1<<maxn];

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    for (int msk = 0; msk < (1<<m); msk++) {
        // cout << msk << ' ' << dp[msk].F << ' ' << dp[msk].S << '\n';
        if (dp[msk].F == n) {
            cout << "YES\n"; return 0;
        }
        for (int i = 0; i < m; i++) {
            if (msk&(1<<i)) continue;
            if (dp[msk].S+b[i] == a[dp[msk].F]) dp[msk+(1<<i)] = mp(dp[msk].F+1, 0);
            else if (dp[msk].S+b[i] < a[dp[msk].F]) dp[msk+(1<<i)] = mp(dp[msk].F, dp[msk].S+b[i]);
        }
    }
    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...