제출 #1286410

#제출 시각아이디문제언어결과실행 시간메모리
1286410kutomei3은행 (IZhO14_bank)C++20
19 / 100
2 ms576 KiB
#include <bits/stdc++.h>
using namespace std;

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

    int n, m;
    cin >> n >> m;
    
    int a[n], b[m];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int j = 0; j < m; j++) cin >> b[j];

    vector<int> au(m, true);
    for (int p = 0; p < n; p++) {
        vector<int> dp(1001, 0), lu(1001, -1);
        dp[0] = 1;

        for (int i = 0; i < m; i++) {
            if (!au[i]) continue;
            for (int j = 1000; j >= b[i]; j--) {
                if (dp[j - b[i]]) {
                    dp[j] = 1;
                    lu[j] = i;
                }
            }
        }
        if (!dp[a[p]]) {
            cout << "NO";
            return 0;
        } else {
            int now = a[p];
            while (now > 0) {
                int id = lu[now];
                au[id] = false;
                now -= b[id];
            }
        }
    }

    cout << "YES";

    return 0;
}
/*

i         j
0 1 2 3 4 5 


*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...