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>
#define int long long
#define ii pair<int,int>
#define ff first
#define ss second
using namespace std;
const int maxn = 21;
int n,m,a[maxn],b[maxn];
ii dp[1<<maxn];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n>>m;
for (int i=1;i<=n;i++) cin>>a[i];
for (int i=1;i<=m;i++) cin>>b[i];
for (int i=1;i<1<<m;i++) dp[i]={-1,-1};
dp[0]={1,0};
for (int mask=0;mask<1<<m;mask++)
{
for (int j=1;j<=m;j++) if (mask>>(j-1)&1)
{
int pre = mask ^ (1<<(j-1));
if (dp[pre].ff==-1) continue;
int now = dp[pre].ss + b[j];
int need = a[dp[pre].ff];
if (now < need) dp[mask] = {dp[pre].ff,now};
else if (now == need) dp[mask] = {dp[pre].ff + 1, 0};
}
if (dp[mask].ff == n+1) return cout<<"YES",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... |