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 = 25;
int n;
int worker[maxn];
bool f(int nm, vector <int> a)
{
    if (nm == n)
    {
        return true;
    }
    int n = int(a.size());
    int sum = worker[nm];
    bool flag = false;
    for(int i = 0; i < (1 << n) && !flag; i++)
    {
        int val = 0;
        for(int j = 0; j < n; j++)
        {
            if ((i & (1 << j)) > 0)
            {
                val += a[j];
            }
        }
        if (sum == val)
        {
            vector <int> vc;
            for(int j = 0; j < n; j++)
            {
                if ((i & (1 << j)) > 0)
                {
                    vc.pb(a[j]);
                }
            }
            flag = f(nm + 1, vc);
        }
    }
    return flag;
}
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 m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        cin >> worker[i];
    }
    vector <int> a(m);
    for(int i = 0; i < m; i++)
    {
        cin >> a[i];
    }
    if (f(0, a))
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
    return 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... |