# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1007896 | arashmemar | Bank (IZhO14_bank) | C++17 | 0 ms | 0 KiB |
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;
stdin >> n >> m;
for (int i = 0;i < n;i++)
{
stdin >> 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++)
{
stdin >> 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)
{
stdout << "YES";
}
else
{
stdout << "NO";
}
return 0;
}