제출 #1277970

#제출 시각아이디문제언어결과실행 시간메모리
1277970bnijaamaa은행 (IZhO14_bank)C++20
19 / 100
2 ms584 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define nn '\n'
#define pb push_back

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < m; ++i) cin >> b[i];
    multiset<int> st(all(b));
    bool ok = false;
    for (int k = 0; k < n; ++k) {
        int cnt = a[k];
        vector<int> v(all(st));
        int sz = v.size();
        vector<bool> dp(cnt + 1, false);
        vector<int> from(cnt + 1, -1);
        dp[0] = true;
        for (int i = 0; i < sz; ++i) {
            for (int j = cnt; j >= v[i]; --j) {
                if (dp[j - v[i]] && !dp[j]) {
                    dp[j] = true;
                    from[j] = i;
                }
            }
        }
        if (!dp[cnt]) {
            ok = true;
            break;
        }
        int j = cnt;
        multiset<int> us;
        while (j > 0) {
            us.insert(v[from[j]]);
            j -= v[from[j]];
        }
        for (int it : us) {
            st.erase(st.find(it));
        }
    }
    cout << (ok ? "NO" : "YES") ;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...