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];
}
pair<int, int> dp[1<<b];
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 + bv[i]>av[valide])rest =bv[i];
if(rest + bv[i]==av[valide]){
valide+=1;
rest=0;
}
if(rest+bv[i]<av[valide]){
rest+=bv[i];
}
dp[s]=max(dp[s], make_pair(valide, rest));
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... |