#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprng(i, a, b) for (int i = (a); i < (b); i++)
#define MOD 1000000007
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
void setIO(const string &name = "") {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (name.size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
int dr[] { 0, 1, 0, -1 };
int dc[] { 1, 0, -1, 0 };
int main() {
setIO();
int m, n;
cin >> n >> m;
vi people(n), notes(m);
rep (i, n) cin >> people[i];
rep (i, m) cin >> notes[i];
vector<pii> dp((1 << m), {-1, -1});
dp[0] = {0, 0};
for (int mask = 1; mask < (1 << m); mask++) {
for (int last = 0; last < m; last++) {
if (!(mask & (1 << last))) continue;
auto prev = dp[mask ^ (1 << last)];
if (prev.f == -1) continue;
if (prev.s + notes[last] < people[prev.f]) {
dp[mask] = { prev.f, prev.s + notes[last] };
} else if (prev.s + notes[last] == people[prev.f]) {
dp[mask] = { prev.f + 1, 0 };
}
}
if (dp[mask].f == n) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'void setIO(const std::string&)':
bank.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |