#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define SZ(x) ((int) (x).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define debug(x) cerr << "[" << #x << " = " << (x) << "]" << endl
#define left __left
#define right __right
#define prev __prev
#define fi first
#define se second
template <class X, class Y>
bool maximize(X &x, Y y) {
if (x < y) return x = y, true;
else return false;
}
template <class X, class Y>
bool minimize(X &x, Y y) {
if (x > y) return x = y, true;
else return false;
}
int numPer, numNotes;
#define MAX_N 30
int val[MAX_N + 2], bill[MAX_N + 2];
namespace subtask1 {
bool check() {
return (numPer == 1);
}
void solve() {
bool ok = false;
FOR(mask, 0, MASK(numNotes) - 1) {
if (ok) break;
int ans = 0;
FOR(i, 0, numNotes - 1) if (BIT(mask, i)) ans += bill[i + 1];
ok |= (ans == val[1]);
}
cout << (ok ? "YES" : "NO");
}
};
namespace subtask2 {
bool check() {
return (numPer <= 10 && numNotes <= 10);
}
void solve() {
vector <int> perm;
FOR(i, 1, numNotes) perm.push_back(i);
bool ok = false;
do {
if (ok) break;
int i = 1, ans = 0;
FOR(j, 1, numNotes) {
int id = perm[j - 1];
ans += bill[id];
if (ans > val[i]) break;
else if (ans == val[i]) {
++i;
ans = 0;
}
}
ok |= (i > numPer);
} while (next_permutation(ALL(perm)));
cout << (ok ? "YES": "NO");
}
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(nullptr);
cin >> numPer >> numNotes;
FOR(i, 1, numPer) cin >> val[i];
FOR(i, 1, numNotes) cin >> bill[i];
// if (subtask1 :: check()) return subtask1 :: solve(), 0;
// if (subtask2 :: check())
return subtask2 :: solve(), 0;
return 0;
}
/* Discipline - Calm */
# | 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... |