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;
vector<long long>c[1009];
long long a[1009];
long long b[1009];
long long dp[21][1<<20];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("bank.in","r",stdin);
//freopen("bank.out","w",stdout);
int 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];
for (int i=0;i<(1<<m);i++){
long long temp=0;
for (int j=0;j<m;j++){
if (i>>j&1){
temp+=b[j+1];
}
}
if (temp<=1000){
c[temp].push_back(i);
}
}
dp[0][0]=1;
for (int i=1;i<=n;i++){
for (int j=0;j<(1<<m);j++){
if (dp[i-1][j]==1){
for (auto v:c[a[i]]){
if ((j&v)==0){
dp[i][j+v]=1;
}
}
}
}
}
for (int j=0;j<(1<<m);j++){
if (dp[n][j]==1){
cout<<"YES";
return 0;
}
}
cout<<"NO";
return 0;
}
# | 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... |