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>
#define int long long
using namespace std;
const int maxn=(1<<20);
int n,m,a[21],b[21];
pair<int,int> dp[maxn];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<m;i++) cin>>b[i];
for(int mask=0;mask<(1<<m);mask++){
if(dp[mask].first==n){
cout<<"YES";
return 0;
}
for(int i=0;i<m;i++){
if((mask>>i & 1)==0){
int nxt=mask^(1<<i);
if(dp[mask].second+b[i]>a[dp[mask].first]) continue;
dp[nxt].second=dp[mask].second+b[i];
dp[nxt].first=dp[mask].first;
if(dp[nxt].second==a[dp[nxt].first]){
dp[nxt].first++;
dp[nxt].second=0;
}
}
}
}
cout<<"NO";
}
# | 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... |