This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* -> Written by <-
   -----------
  |K_A_Z_A_M_A|
  |___________|
  |    ___    |
  |   (^_^)   |
  |  /( | )\  |
  |____|_|____|
    H O A N G
*/
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
using ll = long long;
using db = double;
//using int = long long
#define F               first
#define S               second
#define eb              emplace_back
#define endl            '\n'
#define sz(x)           ((int)x.size())
#define all(x)          x.begin(), x.end()
#define bit(x, i)       (((x) >> (i)) & 1)
#define fr(i,a,b)       for (int i = (int)(a); i <= (int)(b); ++ i)
#define FR(i,a,b)       for (int i = (int)(a); i < (int)(b); ++ i)
#define frr(i,a,b)      for (int i = (int)(a); i >= (int)(b); -- i)
#define fre(i, a)       for (auto &i : a)
//#define ordered_set     tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...)  {cerr << "[" << #x << "] = [";  _print(x); }
#else
#define debug(x...)
#endif
// ===========================================================================================
const int MOD = 1e9 + 7; const ll MM = (ll)MOD * MOD;
const int base = 1e6; const int B = 32;
const int inf = 1e9 + 7; const ll INF = 1e18 + 7;
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; const int dy8[] = {1, -1, 0, 1, -1, 0, 1, -1};
const int dx4[] = {0, 0, 1, -1}; const int dy4[] = {1, -1, 0, 0};
// code go here
int n, m;
int a[20], b[20];
int f[1<<20], rem[1<<20];
void solve(int tc) {
    cin >> n >> m;
    FR(i, 0, n)
        cin >> a[i];
    FR(i, 0, m)
        cin >> b[i];
    memset(f, -1, sizeof(f));
    memset(rem, -1, sizeof(rem));
    f[0] = rem[0] = 0;
    FR(mask, 1, 1<<m) {
        FR(i, 0, m)
            if (bit(mask, i)) {
                int state = mask - (1 << i);
                if (f[state] == -1)
                    continue;
                int newc = rem[state] + b[i];
                int curc = a[f[state]];
                if (newc < curc) {
                    f[mask] = f[state];
                    rem[mask] = newc; 
                } else if (newc == curc) {
                    f[mask] = f[state] + 1;
                    rem[mask] = 0;
                }
            }
        // debug(mask, f[mask], rem[mask]);
        if (f[mask] == n) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    #define Task ""
    if (fopen(Task".in", "r")) { // for old USACO 
        freopen(Task".in", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    if (fopen(".log", "w")) // for debugging
        freopen(".log", "w", stderr);
    int tc = 1;
    // cin >> tc;
    // prepare();
    fr(i, 1, tc) {
        solve(i);
        // bf();
    }
    return 0;
}
// try your best !!!
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen(Task".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:118:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |         freopen(Task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:121:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  121 |         freopen(".log", "w", stderr);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~| # | 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... |