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;
typedef long long ll;
int A[22],B[22];
int LEFT[(1<<20)],dp[(1<<20)];
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n,m; 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=1; i<(1<<m); i++){
for(int j=0; j<m; j++){
if(!(i&(1<<j))) continue;
int sub = i^(1<<j);
int cur = dp[sub]+1,money = LEFT[sub];
if(cur<=dp[i]) continue;
if(A[cur]==money+B[j]){
dp[i] = cur;
LEFT[i] = 0;
}
else if(dp[sub]>=dp[i]){
dp[i] = dp[sub];
LEFT[i] = LEFT[sub]+B[j];
}
}
if(dp[i]==n){
cout<<"YES";
return 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... |