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 endl '\n'
using namespace std;
constexpr int mod=1e9+7;
void solve()
{
int n,m;
cin>>n>>m;
int a[n]={0},b[m];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
}
vector<array<int,2>>dp((1ll<<20),{-1,-1});
dp[0][0]=0;dp[0][1]=0;
for(int s=1;s<(1ll<<m);s++)
{
for(int i=0;i<m;i++)
{
if(!((s>>i)&1))
{
continue;
}
int h=(s^(1ll<<i));
if(dp[h][0]==-1)
{
continue;
}
int nw=dp[h][1]+b[i];
if(nw==a[dp[h][0]])
{
dp[s][0]=dp[h][0]+1;
dp[s][1]=0;
}
else if(nw<a[dp[h][0]])
{
dp[s][0]=dp[h][0];
dp[s][1]=nw;
}
}
if(dp[s][0]==n)
{
cout<<"YES"<<endl;
return;
}
}
cout<<"NO"<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
// cin>>t;
while(t--)
{
solve();
}
}
# | 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... |