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()
{
int a;
int b;
cin>>a>>b;
vector<int>av(a);
vector<int>bv(b);
for(int i=0;i<a;i++){
cin>>av[i];
}
for(int i =0;i<b;i++){
cin>>bv[i];
}
vector<pair<int, int>> dp(1<<b,{-1,0});
dp[0]={0,0};
for(int s=1;s<(1<<b);s++){
for(int i = 0;i<b;i++){
if(s>>i&1){
auto prev = dp[s^(1<<i)];
int valide = prev.first;
int rest = prev.second;
if(rest == -1)continue;
if(rest + bv[i]==av[valide]){
dp[s].first+=1;
dp[s].second=0;
}
if(rest+bv[i]<av[valide]){
dp[s].second+=bv[i];
}
if(dp[s].first == a){
cout<<"YES";
return 0;
}
}
}
}
cout<<"N0";
}
# | 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... |