This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// oh, these hills, they burn so bright / oh, these hills, they bring me life
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x.size())
#define inf 1000000010
#define linf 0x3f3f3f3f3f3f3f3f
#define mp make_pair
#define f first
#define s second
#define pi pair<int, int>
#ifdef __INTELLISENSE__
#include "/mnt/c/yukon/pp.hpp"
#endif
#ifndef LOCAL
#define endl "\n"
#else
#include "/mnt/c/yukon/pp.hpp"
#endif
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> b(m);
for (int i = 0; i < m; i++) {
cin >> b[i];
}
vector<vector<vector<int>>> combos(n + 1);
for (int i = 1; i <= n; i++) {
vector<vector<vector<int>>> pp(a[i] + 1);
pp[0].push_back(vector<int>());
for (int bank = 0; bank < m; bank++) {
for (int val = 1; val <= a[i]; val++) {
if (val - b[bank] >= 0) {
int bruhmoment = sz(pp[val]);
for (auto kk : pp[val - b[bank]]) {
if (find(all(kk), bank) == kk.end()) {
pp[val].push_back(kk);
}
}
for (int l = bruhmoment; l < sz(pp[val]); l++) {
pp[val][l].push_back(bank);
}
}
}
}
combos[i] = pp[a[i]];
}
vector<vector<bool>> dp(n + 1, vector<bool>(1 << m, false));
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (auto &k : combos[i]) {
vector<int> pos;
int wahhhh = 0;
for (int gg = 0; gg < m; gg++) {
if (find(all(k), gg) == k.end()) {
pos.push_back(gg);
} else {
wahhhh += (1 << gg);
}
}
for (int mask = 0; mask < (1 << sz(pos)); mask++) {
int now = wahhhh;
for (int clown = 0; clown < sz(pos); clown++) {
if ((1 << clown) & mask) {
now += (1 << pos[clown]);
}
}
dp[i][now] = dp[i][now] || dp[i - 1][now - wahhhh];
//cout << i << ' ' << bitset<6>(mask) << ": " << dp[i][mask] << endl;
//cout << "REF: " << i - 1 << ' ' << bitset<6>(before) << endl;
if (i == n && dp[i][now]) {
cout << "YES" << endl;
return 0;
}
}
}
}
cout << "NO" << endl;
}
// don't get stuck on one approach
// question bounds
// flesh out your approach before implementing o.o
// math it out
// ok well X is always possible, how about X + 1 (etc.)
# | 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... |