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>
#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
const ll inf = (ll)1e18 + 7;
const ll N = (ll)1e6 + 7;
int n,m;
int a[21],b[21];
int dp[21][1 << 20];
int t[1 << 20];
int main () {
cin >> n >> m;
for (int i = 1; i <= n; i ++)
cin >> a[i];
for (int i = 0; i < m; i ++)
cin >> b[i];
for (int i = 0; i < (1 << m); i ++) {
int sum = 0;
for (int j = 0; j < m; j ++)
if (i & (1 << j))
sum += b[j];
t[i] = sum;
}
dp[1][0] = 1;
for (int i = 1; i <= n; i ++) {
for (int j = 0; j < (1 << m); j ++) {
if (t[j] == a[i]) {
if (n == 1) {
cout << "YES";
return 0;
}
int o = (j ^ ((1 << m) - 1));
for (int k = 0; k < (1 << m); k ++) {
if (dp[i][o & k] == 1)
dp[i + 1][j | k] = 1;
}
}
}
}
if (n == 1) {
cout << "NO" << endl;
return 0;
}
for (int i = 0; i < (1 << m); i ++) {
if (dp[n + 1][i] == 1) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
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... |