#include <bits/stdc++.h>
#define Y8o "Bank"
#define maxn (int) 25
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define fi(i, a, b) for(int i = a; i <= b; i ++)
#define fid(i, a, b) for(int i = a; i >= b; i --)
//#define f first
//#define s second
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
//        freopen(Y8o".out", "w", stdout);
    }
}
void ctime() {
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
int n, m;
int a[maxn], b[maxn], S[maxn];
int sum[1 << 20];
bool dp[maxn][1 << 20];
void solve() {
    cin >> n >> m;
    fi(i, 1, n) cin >> a[i], S[i] = S[i - 1] + a[i];
    fi(i, 1, m) cin >> b[i];
    fi(mask, 0, (1 << m) - 1) {
        fi(i, 1, m) if(gb(mask, i - 1)) sum[mask] += b[i];
    }
    dp[1][0] = 1;
    fi(i, 1, n) {
        fi(mask, 0, (1 << m) - 1) {
            fi(j, 1, m) if(!gb(mask, j - 1)) {
                int nw_mask = mask ^ (1 << (j - 1));
                if(sum[nw_mask] <= S[i]) dp[i][nw_mask] = max(dp[i][nw_mask], dp[i][mask]);
                else if(sum[nw_mask] == S[i]) dp[i + 1][nw_mask] = max(dp[i + 1][nw_mask], dp[i][mask]);
            }
        }
    }
    int ans = 0;
    fi(mask, 0, (1 << m) - 1) {
        if(sum[mask] == S[n]) ans = max(ans, 1*dp[n][mask]);
    }
    if(ans) cout << "YES";
    else cout << "NO";
}
int main() {
    iof();
    int nTest = 1;
//    cin >> nTest;
    while(nTest --) {
        solve();
    }
    ctime();
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'void iof()':
bank.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |