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;
const int MAXN=22;
const int MAXM=(1<<MAXN);
bool dp[MAXM];
int a[MAXN],n,m;
int b[MAXN], pref[MAXN];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
pref[i]=pref[i-1]+a[i];
}
for(int j=1;j<=m;j++)
{
cin>>b[j];
}
dp[0]=1;
for(int mask=0;mask<(1<<m);mask++)
{
if(!dp[mask])continue;
//cout<<mask<<endl;
int i=0;
int sum=0;
for(int j=0;j<m;j++)
{
if(mask&(1<<j))
{
sum+=b[j+1];
}
}
while(i<n&&pref[i+1]<=sum)
{
i++;
}
if(i==n)
{
cout<<"YES\n";
return 0;
}
for(int j=0;j<m;j++)
{
if(!(mask&(1<<j)))
{
//cout<<sum<<" "<<b[j+1]<<" "<<pref[i+1]<<endl;
if(sum+b[j+1]<=pref[i+1])
{
dp[mask|(1<<j)]=1;
}
}
}
}
cout<<"NO\n";
return 0;
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... |