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 task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 1048576 + 7;
ii dp[mxN];
int n, m, a[mxN], b[mxN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
dp[0].fi = 1;
for (int i = 0; i < (1 << m); i++)
{
if (dp[i].se == a[dp[i].fi])
{
dp[i].fi++;
dp[i].se = 0;
}
if (dp[i].fi > n)
{
cout << "YES";
return 0;
}
for (int j = 0; j < m; j++)
{
int nw = i | (1 << j);
if (nw == i)
continue;
dp[nw] = max(ii(dp[i].fi, dp[i].se + b[j]), dp[nw]);
}
}
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... |