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 a[20],b[20],f[1<<20],g[1<<20];
int main() {
// freopen("1.in","r",stdin);
int n,m,i,j;
cin>>n>>m;
for(i=0;i<n;i++) cin>>a[i];
for(i=0;i<m;i++) cin>>b[i];
for(i=1;i<(1<<m);i++) {
g[i]=1e9;
for(j=0;j<m;j++) {
if(i&(1<<j)) {
if(g[i]<g[i^(1<<j)]+b[j]) continue;
g[i]=g[i^(1<<j)]+b[j];
if(g[i]==a[f[i^(1<<j)]]) {
f[i]=f[i^(1<<j)]+1,g[i]=0;
if(f[i]==n) return printf("YES\n"),0;
break;
}
else f[i]=f[i^(1<<j)];
if(f[i]==n) return printf("YES\n"),0;
}
}
}
printf("NO\n");
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... |