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 <iostream>
#include <vector>
using namespace std;
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(false);
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];
if(n > m){
cout << "NO\n";
return 0;
}
vector<pair<int,int>> dp(1<<m);
dp[0] = {0, 0};
bool ok = false;
for(int mask=0; mask<(1<<m) && !ok; mask++){
for(int i=0; i<m; i++){
if(mask & (1<<i)){
auto prev = dp[mask ^ (1<<i)];
if(prev.second + b[i] == a[prev.first]){
dp[mask] = max(dp[mask], make_pair(prev.first+1, 0));
} else if(prev.second + b[i] < a[prev.first]){
dp[mask] = max(dp[mask], make_pair(prev.first, prev.second + b[i]));
}
}
}
if(dp[mask].first == n) ok = true;
}
cout << (ok ? "YES\n" : "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... |