This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define taskname "bank."
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
int n, m;
int a[20], b[20], dp[1<<20], c[1<<20];
int main()
{
fastio;
cin >> n >> m;
for (int i=0; i<n; ++i) cin >> a[i];
for (int i=0; i<m; ++i) cin >> b[i];
for (int i=1; i<(1<<m); ++i) dp[i]=c[i]=-1;
for (int mask=1; mask<(1<<m); ++mask)
{
for (int i=0; i<m; ++i)
{
if (!(mask&(1<<i))) continue;
int x=mask^(1<<i);
if (dp[x]==-1) continue;
int s=c[x]+b[i];
if (s==a[dp[x]])
dp[mask]=dp[x]+1, c[mask]=0;
else if (s<a[dp[x]])
dp[mask]=dp[x], c[mask]=s;
}
if (dp[mask]==n)
{
cout << "YES"; return 0;
}
}
cout << "NO";
}
# | 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... |