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;
#define all(x) x.begin(),x.end()
#define pb push_back
#define bug(x) cerr<<#x<<" ( "<<x<<endl
using i64=long long;
const int inf=1e9;
main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin>>n>>m;
vector<int>a(n);
vector<int>b(m);
for(auto &c:a)cin>>c;
for(auto &c:b)cin>>c;
vector<pair<int,int>>dp(1<<m,{0,0});
for(int i=1;i<(1<<m);i++)
{
for(int j=0;j<m;j++)
{
if(i&(1<<j))
{
auto nou=dp[i^(1<<j)];
nou.second+=b[nou.first];
if(nou.second==a[nou.first])
{
nou.first++;
nou.second=0;
}
if(nou.first==n)
{
cout<<"YES\n";
return 0;
}
dp[i]=max(dp[i],nou);
}
}
}
cout<<"NO\n";
}
Compilation message (stderr)
bank.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main()
| ^~~~
# | 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... |