# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085811 | ThylOne | Bank (IZhO14_bank) | C++14 | 103 ms | 4560 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.
//####################
//Bank
//####################
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[20];
int b[20];
int sum[20];
int dp[(1<<20)+1];
int solve(int bitmask){
if(dp[bitmask]!=-1)return dp[bitmask];
int pos = 0;
int s = 0;
for(int i = 0;i<m;i++)if((bitmask>>i)&1)s+=b[i];
int bonus = 0;
for(int i = 0;i<n;i++)
if(sum[i]==s) bonus = 1;
int re = bonus;
for(int i = 0;i<m;i++){
if(!((bitmask>>i)&1)){
re =max(re,bonus+ solve(bitmask ^ (1<<i)));
}
}
return dp[bitmask]=re;
}
signed main(){
for(int i = 0;i<(1<<20)+1;i++)dp[i] = -1;
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i= 0;i<n;i++)cin>>a[i];
for(int i = 0;i<m;i++)cin>>b[i];
sum[0] = a[0];
for(int i = 1;i<n;i++)sum[i] = a[i] + sum[i-1];
int re = solve(0);
if(solve(0)==n)
cout << "YES" << endl;
else
cout << "NO" << endl;;
return 0;
};
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... |