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;
int main()
{
int n,m;
cin >> n >> m;
int people[n],note[m];
for(int i=0;i<n;i++)
cin >> people[i];
for(int i=0;i<m;i++)
cin >> note[i];
vector<int> moneyleft(1<<m,-1),paidpeople(1<<m,-1);
moneyleft[0]=paidpeople[0]=0;
for(int subset=1;subset<(1<<m);subset++)
{
for(int j=0;j<m;j++)
{
int prev=subset^(1<<j);
if(subset&(1<<j)&&paidpeople[prev]!=-1)
{
int current=moneyleft[prev]+note[j];
int target=people[paidpeople[prev]];
if(current<target)
{
moneyleft[subset]=current;
paidpeople[subset]=paidpeople[prev];
}
else if(current==target)
{
moneyleft[subset]=0;
paidpeople[subset]=paidpeople[prev]+1;
}
}
}
if(paidpeople[subset]==n)
{
cout << "YES";
return 0;
}
}
cout << "NO";
}
# | 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... |