제출 #1246441

#제출 시각아이디문제언어결과실행 시간메모리
1246441t6stksBank (IZhO14_bank)C++20
100 / 100
102 ms8520 KiB
#include <bits/stdc++.h>
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vii = vector<pii>;
using vll = vector<pll>;

const int INF = 0x3f3f3f3f;
void sol() {
    int n, m;
    cin >> n >> m;
    vi a(n), b(m);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    vii dp(1 << m, {0, -INF});
    dp[0] = {0, 0};
    for (int i = 0; i < (1 << m); i++) {
        if (dp[i].F == n) {
            cout << "YES\n";
            return;
        }
        for (int j = 0; j < m; j++) {
            if (i >> j & 1) continue;
            pii nw = dp[i];
            nw.S += b[j];
            if (nw.S > a[nw.F]) continue;
            if (nw.S == a[nw.F]) nw.F++, nw.S = 0;
            dp[i | (1 << j)] = max(dp[i | (1 << j)], nw);
        }
    }
    cout << "NO\n";
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    sol();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...