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;
#define bit(n,i) ((n>>i)&1)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define ep emplace_back
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
#define ll long long
const int MOD=1e9+7;
const int base=31;
const int N=1e6+5;
int n,m,leftover[1<<20],num_people[1<<20],bank[20],salary[20];
int main()
{
#ifdef Hyojin
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif //Hyojin
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for (int i=0;i<n;i++) cin>>salary[i];
for (int i=0;i<m;i++) cin>>bank[i];
memset(num_people,-1,sizeof num_people);
memset(leftover,-1,sizeof leftover);
leftover[0]=num_people[0]=0;
for (int mask=0;mask<(1<<m);mask++)
{
for (int i=0;i<m;i++)
{
if (bit(mask,i))
{
int premask=mask-(1<<i);
if (num_people[premask]==-1) continue;
int total=leftover[premask]+bank[i];
int cur=salary[num_people[premask]];
if (total<cur)
{
leftover[mask]=total;
num_people[mask]=num_people[premask];
}
if (total==cur)
{
leftover[mask]=0;
num_people[mask]=num_people[premask]+1;
}
}
}
if (num_people[mask]==n)
{
cout<<"YES";
return 0;
}
}
cout<<"NO";
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... |