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<<21];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
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];
dp[0]={0, 0};
for (int state=0;state<(1<<m);state++) {
if (dp[state].first==n) {
cout << "YES";
return 0;
}
for (int i=0;i<m;i++) {
if (state&(1<<i)) continue;
pair<int,int> new_state;
if (dp[state].second+b[i]==a[dp[state].first])
new_state={dp[state].first+1, 0};
else
new_state={dp[state].first, dp[state].second+b[i]};
dp[state|(1<<i)]=max(dp[state|(1<<i)], new_state);
}
}
cout << "NO";
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... |