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 ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define vr(v) v.begin(),v.end()
#define rv(v) v.rbegin(),v.rend()
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Davit cout.tie(NULL);
using namespace std;
//#include "algo/debug.h"
//mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 myrand(373);
//mt19937 myrand(373);
const int N = 20, M = (1 << N);
int a[N], b[N];
pair<int, int> dp[M];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < m; ++i) cin >> b[i];
for (int i = 1; i < M; ++i) dp[i] = {-1, 0};
for (int mask = 1; mask < (1 << m); mask++) {
for (int i = 0; i < m; i++) {
if ((mask >> i) & 1) {
pair<int, int> dpj = dp[mask ^ (1 << i)];
if (dpj.ff == -1)continue;
if (dpj.ss + b[i] < a[dpj.ff]) {
dp[mask] = {dpj.ff, dpj.ss + b[i]};
} else if (dpj.ss + b[i] == a[dpj.ff]) {
dp[mask] = {dpj.ff + 1, 0};
}
}
}
if (dp[mask].ff == n) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO\n";
}
# | 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... |