# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
576339 | Springmike | Bank (IZhO14_bank) | C++17 | 139 ms | 16820 KiB |
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 ll long long
const ll MOD=1e9+7;
pair<ll,ll>dp[2000005];
ll a[2000005],b[2000005];
void giai()
{
ll n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=m;i++)
cin>>b[i];
dp[0].first=0;
dp[0].second=0;
for(int mask=1;mask<=(1<<m)-1;mask++)
{
for(int i=1;i<=m;i++)
if(mask&(1<<(i-1)))
{
pair<ll,ll>num;
num=dp[mask^(1<<(i-1))];
num.second+=b[i];
if(num.second==a[num.first+1])
{
++num.first;
if(num.first==n)
{
cout<<"YES";
return;
}
num.second=0;
}
dp[mask]=max(dp[mask],num);
}
}
cout<<"NO"<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
if(fopen("CF.inp","r"))
{
freopen("CF.inp","r",stdin);
freopen("CF.out","w",stdout);
}
ll t;
giai();
}
Compilation message (stderr)
# | 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... |