# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
839167 | DeathIsAwe | Bank (IZhO14_bank) | Cpython 3 | 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 dp[10000000],rem[10000000];
int main() {
int n,m; cin >> n >> m;
vector<int> people(n),notes(m);
for (int i=0;i<n;i++) {
cin >> people[i];
}
for (int i=0;i<m;i++) {
cin >> notes[i];
}
int miss,maxdp,temp,temp2; dp[0]=0; rem[0]=0;
for (int i=1;i<(int)pow(2,m);i++) {
temp2=1;
maxdp=-1;
for (int j=0;j<m;j++) {
if ((i^temp2)<i && maxdp<dp[(i^temp2)]) {
temp=(i^temp2);
maxdp=dp[(i^temp2)];
miss=j;
}
temp2*=2;
}
if (rem[temp]+notes[miss]==people[maxdp]) {
dp[i]=maxdp+1;
rem[i]=0;
} else {
dp[i]=maxdp;
rem[i]=rem[temp]+notes[miss];
}
if (dp[i]==n) {
cout << "YES"; return 0;
}
}
cout << "NO";
}