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;
pair<int,int> dp[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 msk=0;msk<1<<m;msk++) {
for(int last=0;last<m;last++) {
if((msk&(1<<last))==0) continue;
if(b[last]+dp[msk^(1<<last)].second==a[dp[msk^(1<<last)].first])
dp[msk] = {dp[msk^(1<<last)].first+1,0};
else dp[msk] = max(dp[msk], {dp[msk^(1<<last)].first, b[last]+dp[msk^(1<<last)].second});
if(dp[msk].first==n) {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
}
# | 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... |