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 <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
#include <iterator>
#include <stack>
#include <map>
#include <math.h>
#include <bitset>
#include <deque>
#include <string>
#include <tuple>
#include <queue>
#include <numeric>
#include <complex>
#include <assert.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define ld long long double
#define rep(i, a, b) for (long long i = a; i <= b; i++)
#define mod 1000000007ll
#define INF 1e18
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin (), (x).end ()
#define sz(x) (ll) (x).size ()
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define rank rnk
#define log lg
#define fast \
ios_base::sync_with_stdio (false); \
cin.tie (NULL); \
cout.tie (NULL)
using namespace std;
signed main()
{
fast;
freopen("bank.in","r",stdin);
freopen("bank.out","w",stdout);
ll n,m;
cin>>n>>m;
ll s1=0, s2=0;
ll p[n], notes[m];
rep(i,0,n-1)
cin>>p[i], s1+=p[i];
rep(i,0,m-1)
cin>>notes[i], s2+=notes[i];
if(s1>s2)
{
cout<<"NO"<<endl;
exit(0);
}
vector <ll> validmasks[n];
rep(i,0,n-1)
rep(mask,0,(1<<m)-1)
{
ll s=0;
rep(idx,0,m-1)
if(mask&(1ll<<idx))
s+=notes[idx];
if(s==p[i])
validmasks[i].pb(mask);
}
bool cancover[n][(1<<m)];
rep(i,0,n-1)
rep(mask,0,(1<<m)-1)
cancover[i][mask]=false;
for(auto mask:validmasks[0])
cancover[0][mask]=true;
rep(i,1,n-1)
rep(mask,0,(1<<m)-1)
{
for(auto submask:validmasks[i])
if((submask&(~mask))==0)
cancover[i][mask]|=cancover[i-1][mask^submask];
}
bool ans=false;
rep(mask,0,(1<<m)-1)
ans|=cancover[n-1][mask];
cout<<(ans?"YES":"NO");
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:45:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | freopen("bank.in","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bank.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | freopen("bank.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |