# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
382557 | mariowong | Bank (IZhO14_bank) | C++14 | 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;
int m,n,a[25],b[25],val[1100000];
vector <int> v,ps[25],v2;
bool dp[25][1100000];
int main(){
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i=1;i<=n;i++){
cin >> a[i];
}
for (int i=0;i<m;i++){
cin >> b[i];
}
for (int i=0;i<(1<<m);i++){
for (int j=0;j<m;j++){
if ((i&(1<<j)) > 0)
val[i]+=b[j];
}
for (int j=1;j<=n;j++){
if (val[i] == a[j])
ps[j].push_back(i);
}
}
v.push_back(0);
for (int i=1;i<=n;i++){
v2.clear();
for (int j=0;j<ps[i].size();j++){
for (int k=0;k<v.size();k++){
if ((v[k]&ps[i][j]) == 0 && !dp[v[k]&ps[i][j]]){
v2.push_back(v[k]+ps[i][j]);
dp[v[k]&ps[i][j]]=true;
}
}
}
v.clear(); v=v2;
if ((int)v.size() == 0){
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
return 0;
}