This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/** @BY_KUTBILIM **/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).end()
int main(){
ios_base::sync_with_stdio(false);
cin.tie();
int n, m;
cin >> n >> m;
vector<vector<bool>> dp(n, vector<bool>((1 << m), false));
int a[n], b[m];
for(int i = 0; i < n; i++)cin >> a[i];
for(int i = 0; i < m; i++)cin >> b[i];
vector<vector<int>> can(1001);
for(int mask = 0; mask < (1 << m); mask++){
int sum = 0;
for(int i = 0; i < m; i++){
if((1 << i) & mask)sum += b[i];
}
if(sum <= 1000){
can[sum].pb(mask);
}
}
for(auto mask : can[a[0]])dp[0][mask] = true;
for(int i = 1; i < n; i++){
bool find = false;
for(int mask = 0; mask < (1 << m); mask++){
if(!dp[i-1][mask])continue;
for(auto j : can[a[i]]){
if((mask & j) == 0){
dp[i][mask|j] = true;
find = true;
}
}
}
if(!find)break;
}
bool ok = false;
for(int mask = 0; mask < (1 << m); mask++){
if(dp[n-1][mask])ok = true;
}
if(ok)cout << "YES\n";
else cout << "NO\n";
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... |