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[1<<20], lef[1<<20];
int main(){
int n, m;
cin>>n>>m;
vector<int> a(n), b(m);
for(int i=0;i<n;++i){
cin>>a[i];
}
for(int i=0;i<m;++i){
cin>>b[i];
}
for(int mask=1;mask<(1<<m);++mask){
dp[mask]=-1e9;
for(int bit=0;bit<m;++bit){
if(!(mask&(1<<bit))) continue;
int pmask=mask^(1<<bit);
if(dp[pmask]<0) continue;
int val=lef[pmask]+b[bit];
if(val<a[dp[pmask]]){
dp[mask]=dp[pmask];
lef[mask]=val;
}
else if(val==a[dp[pmask]]){
dp[mask]=dp[pmask]+1;
lef[mask]=0;
}
}
if(dp[mask]==n){
cout<<"YES\n";
return 0;
}
}
cout<<"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... |