#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> s(n);
    vector<int> notes(m);
    for(int i = 0; i < n; i++) cin >> s[i];
    for(int i = 0; i < m; i++) cin >> notes[i];
    vector<int> covered((1<<m) + 1, 0);
    vector<int> notes_left((1<<m) + 1, 0);
    for(int i = 1; i < (1<<m); i++){
        for(int j = 0; j < m; j++){
            if((1<<j) & i){
                int prev = (1<<j) ^ i;
                int curr_req = s[covered[prev]];
                int prev_left = notes_left[prev];
                int amt = prev_left + notes[j];
                if(amt < curr_req){
                    covered[i] = covered[prev];
                    notes_left[i] = prev_left + notes[j];
                }
                else if(amt == curr_req){
                    covered[i] = covered[prev] + 1;
                    notes_left[i] = 0;
                }
                else{
                    //amt > curr_req
                    notes_left[i] = amt;
                }
            }
        }
        if(covered[i] == n){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}
/*
1 5
8 
4 2 5 1 3
2 6
9 10
5 4 8 6 3 11
*/
| # | 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... |