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>
using namespace std ;
 
#define ff first
#define ss second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ones(x) __builtin_popcount(x)
#define remove(v)  v.erase(unique(all(v)), v.end())
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
 
#ifdef local
#include "C:\debug.h"
#else
#define dbg(x...) 42
#endif
#define int long long
 
const int N = 2e6 + 2 ;
const int MOD = 1e9 + 7 ;
const int P = 1007 ;
 
int n , m , a[21] , b[21] , pref[21] ;
unordered_map<int,int> dp[21] ;
 
int go(int i , int mask , int cur) {
    if(cur == pref[i]) {
        dp[i][mask] = 1 ;
        i++ ;
    } 
    if(dp[i].count(mask)) return dp[i][mask] ;
    if(i > n) {
        cout << "YES\n" ;
        exit(0) ;
        return 1 ;
    }
    int ans = 0 ;
    rep(j , 0 , m - 1) {
        if(!(mask >> j & 1) && cur + b[j + 1] <= pref[i]) {
            ans |= go(i , (mask | (1 << j)) , cur + b[j + 1]) ;
        }
    }
    dp[i][mask] = ans ;
    return dp[i][mask] ;
}
 
void solve(){
    cin >> n >> m ;
    rep(i , 1 , n) cin >> a[i] ;
    rep(i , 1 , m) cin >> b[i] ;
    rep(i , 1 , n) pref[i] = pref[i - 1] + a[i] ;
    bool ok = go(1 , 0 , 0) ;
    cout << "NO\n" ;
}
 
signed main () {
	// ios::sync_with_stdio(false) ;
	// cin.tie(0) ;
	int test = 1 ;
	// cin >> test ; 
	for(int i = 1 ; i <= test ; i++) {
		solve() ;
	}
}
Compilation message (stderr)
bank.cpp: In function 'void solve()':
bank.cpp:56:10: warning: unused variable 'ok' [-Wunused-variable]
   56 |     bool ok = go(1 , 0 , 0) ;
      |          ^~| # | 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... |