This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma optimize ("-Ofast")
//#pragma comment (linker, "-STACK 99999999")
#define ld long double
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
//#define int long long
using namespace std;
const int maxn = 22;
int inf = 1e9 + 15;
int a[maxn], b[maxn];
bool dp[maxn][1 << maxn];
//mask, count of pays
int32_t main()
{
#ifdef LOCAL
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#else
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for(int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    if (n > m)
    {
        cout << "NO";
        return 0;
    }
    vector <pair <int, int>> vc;
    for(int i = 0; i < (1 << m); i++)
    {
        int val = 0;
        for(int j = 0; j < m; j++)
        {
            if ((i & (1 << j)) > 0)
            {
                val += b[j];
            }
        }
        vc.pb({val, i});
    }
    sort(vc.begin(), vc.end());
    dp[0][0] = true;
    for(int i = 0; i < n; i++)
        for(int mask = 0; mask < (1 << m); mask++)
    {
        if (!dp[i][mask])
        {
            continue;
        }
        auto it = lower_bound(vc.begin(), vc.end(), make_pair(a[i], 0));
        for(it; it != vc.end() && (*it).F == a[i]; it++)
        {
            if (((*it).S & mask) == 0)
            {
                dp[i + 1][(*it).S | mask] = true;
            }
        }
    }
    bool f = false;
    for(int mask = 0; mask < (1 << m); mask++)
    {
        if (dp[n][mask])
        {
            f = true;
            break;
        }
    }
    if (f)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
    return 0;
}
Compilation message (stderr)
bank.cpp:3:0: warning: ignoring #pragma optimize  [-Wunknown-pragmas]
 #pragma optimize ("-Ofast")
 
bank.cpp: In function 'int32_t main()':
bank.cpp:72:15: warning: statement has no effect [-Wunused-value]
         for(it; it != vc.end() && (*it).F == a[i]; it++)
               ^| # | 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... |