제출 #556318

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

#ifdef VSLOCAL
#include "debug/d.h"
#endif
#ifdef LOCAL
#include "../../debug/d.h"
#endif

using namespace std;

using ll = long long;
using ld = long double;

#if defined(LOCAL) || defined(VSLOCAL)
#define dbg(...) line_info(__LINE__, #__VA_ARGS__), dbg1(__VA_ARGS__)
void nline() { cerr << '\n'; }
#else
#define dbg(...) 0
void nline() {}
#endif

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("log.txt", "w", stderr);
    #endif

    int N, M;
    cin >> N >> M;

    vector<int> a (N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    vector<int> b (M);
    for (int i = 0; i < M; ++i) {
        cin >> b[i];
    }

    vector<pair<int, int>> dp (1 << M);

    for (int i = 1; i < (1 << M); ++i) {
        for (int j = 0; j < M; ++j) {
            if (i & (1 << j)) {
                auto [num, val] = dp[i ^ (1 << j)];
                if (num == N) {
                    dp[i] = {N, 0};
                    break;
                }
                if (val + b[j] > a[num]) dp[i] = max(dp[i], dp[i ^ (1 << j)]);
                else if (val + b[j] == a[num]) dp[i] = max(dp[i], {num + 1, 0});
                else dp[i] = max(dp[i], {num, val + b[j]});
            }
        }
    }
    if (dp[(1 << M) - 1].first == N) cout << "YES\n";
    else cout << "NO\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...