#include <bits/stdc++.h>
using namespace std;
int necesar[21] , suma[1 << 20];
bool posibil[1 << 20];
int main ()
{
ios :: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int cantitate[2];
cin >> cantitate[0] >> cantitate[1];
for (int indice = 1 ; indice <= cantitate[0] ; indice++)
{ cin >> necesar[indice]; }
for (int indice = 0 , termen ; indice < cantitate[1] ; indice++)
{
cin >> termen;
for (int masca = 0 ; masca < (1 << (cantitate[1] - 1)) ; masca++)
{ suma[(masca & ((1 << indice) - 1)) | (1 << indice) | ((masca >> indice) << (indice + 1))] += termen; }
}
posibil[0] = true;
for (int indice = 1 , actual = 0 ; indice <= cantitate[0] ; indice++)
{
for (int masca = 1 ; masca < (1 << cantitate[1]) ; masca++) {
for (int __masca = masca ; __masca ; __masca ^= (__masca & -__masca))
{ posibil[masca] |= posibil[masca ^ (__masca & -__masca)]; }
}
actual += necesar[indice];
for (int masca = 0 ; masca < (1 << cantitate[1]) ; masca++)
{ posibil[masca] &= (suma[masca] == actual); }
}
bool gasit = false;
for (int masca = 1 ; masca < (1 << cantitate[1]) ; masca++)
{ gasit |= posibil[masca]; }
cout << (gasit ? "YES" : "NO");
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... |