# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1136358 | classic | Bank (IZhO14_bank) | C++20 | 36 ms | 24388 KiB |
// mode: short code
/*
practicing..
*/
#include<bits/stdc++.h>
int main() {
freopen("bank.in", "r", stdin);
freopen("bank.out", "w", stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n, m;
std::cin >> n >> m;
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
std::vector<int> b(m);
for (int i = 0; i < m; i++) {
std::cin >> b[i];
}
std::vector<int> cnt(1 << m, -1), rem(1 << m, -1);
cnt[0] = 0;
rem[0] = 0;
for (int i = 1; i < (1 << m); i++) {
for (int j = 0; j < m; j++) {
if (!(i & (1 << j))) {
continue;
}
int p = (i ^ (1 << j));
if (cnt[p] == -1) {
continue;
}
int nxt = rem[p] + b[j];
int need = a[cnt[p]];
if (nxt < need) {
cnt[i] = cnt[p];
rem[i] = nxt;
} else if (nxt == need) {
cnt[i] = cnt[p] + 1;
rem[i] = 0;
}
}
if (cnt[i] == n) {
std::cout << "YES";
return 0;
}
}
std::cout << "NO";
return 0;
}
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... |