# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1131505 | ahmedsahlol | Bank (IZhO14_bank) | C++20 | 70 ms | 164424 KiB |
#include <bits/stdc++.h>
#define int long long
#define el '\n'
using namespace std;
const int N = 20;
int n, m, a[N], b[N], dp[N][1LL << N];
int solve(int i, int mask, int sum_now) {
if (i == n) return 1;
int &ret = dp[i][mask];
if (~ret) return ret;
ret = 0;
for (int j = 0; j < m; ++j) {
if ((mask >> j) & 1) continue;
if (sum_now + b[j] <= a[i]) {
if (a[i] == sum_now + b[j]) ret |= solve(i + 1, mask | (1LL << j), 0);
else ret |= solve(i, mask | (1LL << j), sum_now + b[j]);
}
}
return ret;
}
void work() {
cin >> n >> m;
memset(dp, -1, sizeof dp);
for (int i = 0; i < n; ++i)cin >> a[i];
for (int i = 0; i < m; ++i)cin >> b[i];
cout << (solve(0, 0, 0) ? "YES" : "NO") << el;
}
int32_t main() {
freopen("bank.in", "r", stdin);
freopen("bank.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc = 1;
// cin >> tc;
while (tc--) {
work();
}
}
Compilation message (stderr)
# | 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... |