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 ll long long
#define mod 1000000007
#define dim 100002
#define lim 1000000
#define mdim 1501
#define mult 2e9
#define maxx 200000
#define simaimult 1e17
#define piii pair<int,pair<int,int> >
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define nr_biti __builtin_popcount
using namespace std;
ifstream fin("b.in");
ofstream fout("b.out");
int n,m;
int a[22],b[22];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m;
for(int i=0; i<n; i++)
cin >> a[i];
for(int i=0; i<m; i++)
cin >> b[i];
vector<int> dp(1<<m,-1);
vector<int> rest(1<<m,-1);
dp[0]=rest[0]=0;
for(int i=1; i<(1<<m); i++)
{
for(int j=0; j<m; j++)
{
if(!(i&(1<<j)))
continue;
if(dp[i^(1<<j)]==-1)
continue;
if(rest[i^(1<<j)]+b[j]<a[dp[i^(1<<j)]])
{
dp[i]=dp[i^(1<<j)];
rest[i]=rest[i^(1<<j)]+b[j];
}
else if(rest[i^(1<<j)]+b[j]==a[dp[i^(1<<j)]])
{
dp[i]=dp[i^(1<<j)]+1;
rest[i]=0;
}
}
if(dp[i]==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... |