#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1001;
int n, m, a[N], b[N];
bool bit(int mask, int pos){
return (mask>>(pos-1))&1;
}
int main(){
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i= 1; i <= m; ++i)
cin >> b[i];
sort(a+1, a+n+1);
sort(b+1, b+m+1);
bool ans = true;
vector<int> del;
for (int i = 1; i <= n && ans; ++i){
for (int mask = 0; mask < (1<<(m+1)); ++mask){
del.clear();
int sum = 0;
for (int k = 1; k <= m; ++k){
if (bit(mask, k)){
sum += b[k];
del.push_back(k);
}
}
if (sum==a[i]){
for (int&x: del)
b[x] = 0;
del.clear();
break;
}
}
// cout << "i = " << i << "\t";
// for (int j = 1; j <= m; ++j)
// cout << b[j] << " \n"[j==m];
if (!del.empty())
ans = false;
}
cout << (ans? "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... |