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 ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << endl
#define all(x) x.begin(),x.end()
pii dp[(1<<20) + 10];
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n,m;cin>>n>>m;
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];
sort(a,a+n);
for(int mask=0;mask<(1<<m);mask++)
{
for(int i=0;i<m;i++)
{
if((mask&(1<<i))!=0)
{
dp[mask]=max(dp[mask],{dp[(mask^(1<<i))].fi,dp[(mask^(1<<i))].se+b[i]});
if(dp[mask].se==a[dp[mask].fi]) dp[mask]={dp[mask].fi+1,0};
}
}
}
// for(int mask=0;mask<(1<<m);mask++) cout<<dp[mask].fi<<' ';cout<<'\n';
if(dp[(1<<m)-1].fi!=n) cout<<"NO\n";
else cout<<"YES\n";
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... |