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;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void S()
{
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];
vector <pair<int, int>> dp(1<<m, make_pair(-1, 0));
dp[0] = {0, 0};
for(int mask = 0; mask < (1 << m); mask ++){
for(int i = 0; i < m; i ++){
if((mask >> i) & 1){
auto it = dp[mask ^ (1 << i)];
if(it.first != -1){
if(it.second + b[i] == a[it.first])
it.first ++, it.second = 0;
else
if(it.second + b[i] < a[it.first])
it.second +=b[i];
else
it.first = -1, it.second = 0;
dp[mask] = max(dp[mask], it);
}
}
}
if(dp[mask].first == n){
cout << "YES";
return;
}
}
cout << "NO";
}
int main()
{
IOS;
/*int t;
cin >> t;
while(t --)*/
S();
}
# | 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... |