제출 #1312000

#제출 시각아이디문제언어결과실행 시간메모리
1312000georgeckito은행 (IZhO14_bank)C++20
19 / 100
131 ms580 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define str string
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const int N = 200000;

void solve()
{
    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++)
        cin >> b[i];
    bool ans = 1;
    for (int i = 0; i < n; i++)
    {
        bool found = 0;
        for (int j = 1; j < (1LL << m); j++)
        {
            int sum = 0;
            vector<int> subset;
            for (int k = 0; k < m; k++)
            {
                if (j & (1LL << k) && b[k] != -1)
                {
                    sum += b[k];
                    subset.pb(k);
                }
            }
            if (sum == a[i])
            {
                for (auto x : subset)
                    b[x] = -1;
                found = 1;
                break;
            }
        }
        if (!found)
        {
            ans = 0;
            cout << "NO" << endl;
            return;
        }
    }
    cout << (ans ? "YES" : "NO") << endl;
}

signed main()
{
    fast int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...