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;
long long int a[30], b[30];
int dp[(1 << 20) + 20], ps[30];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0;i < n;i++)
{
cin >> a[i];
}
ps[0] = a[0];
for (int i = 1;i < n;i++)
{
ps[i] = ps[i-1] + a[i];
}
for (int i = 0;i < m;i++)
{
cin >> b[i];
}
for (long long int mask = 1; mask < (1 << m);mask++)
{
int c = 1;
int s = 0;
for (int i = 0;i < m;i++)
{
if (mask & c)
{
s += b[i];
dp[mask] = max(dp[mask], dp[mask - c]);
}
c *= 2;
}
if (s == ps[dp[mask]])
{
dp[mask]++;
}
}
if (dp[(1 << m) - 1] == n)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return 0;
}
# | 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... |