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;
typedef long long ll;
#define pll pair<ll, ll>
#define ppll pair<pll, ll>
#define fll(i, n) for (ll i =0 ; i < n; i++)
#define vll vector<ll>
#define prtv(V) fll(i, V.size()) cout << V[i] << " "; cout << '\n';
ll INF = 2e18;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m;
cin >> n >> m;
vll A(n), B(m); fll(i, n) cin >> A[i];
fll(i, m) cin >> B[i];
A.push_back(0);
vector<pll> ans(1<<m, {0, INF});
ans[0] = {0, A[0]};
fll(s, 1<<m)
{
if (ans[s].first == n && !ans[s].second)
{
cout << "YES\n";
return 0;
}
if (ans[s].second == INF) continue;
fll(i, m)
if (!(s&(1<<i)))
{
if (ans[s].second == B[i])
ans[s|(1<<i)] = {ans[s].first+1, A[ans[s].first+1]};
else if (ans[s].second > B[i])
ans[s|(1<<i)] = {ans[s].first, ans[s].second-B[i]};
}
}
cout << "NO\n";
}
# | 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... |