#include <bits/stdc++.h>
using namespace std;
int necesar[21] , termen[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 = 1 ; indice <= cantitate[1] ; indice++)
{ cin >> termen[indice]; }
for (int masca = 1 ; masca < (1 << cantitate[1]) ; masca++) {
for (int indice = 1 , putere = 1 ; putere <= masca ; indice++ , putere <<= 1) {
if (masca & putere)
{ suma[masca] += termen[indice]; }
}
}
posibil[0] = true;
for (int indice = 1 , actual = 0 ; indice <= cantitate[0] ; indice++)
{
for (int masca = 1 ; masca < (1 << cantitate[1]) ; masca++) {
for (int putere = 1 ; putere <= masca ; putere <<= 1) {
if (masca & putere)
{ posibil[masca] |= posibil[masca ^ putere]; }
}
}
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... |