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 int ll;
const int MAXN = 1e3;
int dp[(1 << 20)];
int a[MAXN];
int b[MAXN];
int pf[MAXN];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
pf[i] = pf[i - 1] + a[i];
}
for (int i = 0; i < m; i++)
cin >> b[i];
for (int mask = 1; mask < (1 << m); mask++)
{
int mx = 0, sum = 0;
for (int i = 0; i < m; i++)
{
if ((mask >> i) & 1)
{
mx = max(mx, dp[mask - (1 << i)]);
sum += b[i];
}
}
if (sum == pf[mx+1])
{
dp[mask] = mx + 1;
}
else
{
dp[mask] = mx;
}
}
if (dp[(1 << m)-1] == n)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
# | 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... |