# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
520334 | krit3379 | Bank (IZhO14_bank) | C++17 | 102 ms | 8620 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 N 20
int a[N],b[N];
pair<int,int> dp[1<<N];
int main(){
int n,m,i,j,pre;
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)scanf("%d",&a[i]);
for(i=0;i<m;i++)scanf("%d",&b[i]);
for(i=0;i<(1<<m);i++){
for(j=0;j<m;j++){
if((i&(1<<j))==0)continue;
pre=i^(1<<j);
auto [last,sum]=dp[pre];
if(sum+b[j]==a[last]){
dp[i]=max(dp[i],make_pair(last+1,0));
}
else{
dp[i]=max(dp[i],make_pair(last,sum+b[j]));
}
}
}
if(dp[(1<<m)-1].first==n)printf("YES");
else printf("NO");
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... |