# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
760982 | Kubogi | Bank (IZhO14_bank) | C++17 | 100 ms | 8632 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
const int maxn = 20;
int n, m, a[maxn], b[maxn], pf[1<<maxn], rem[1<<maxn];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
fileio("");
// freopen("debug.txt", "w", stderr);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
memset(pf, -1, sizeof pf);
pf[0] = 0;
for (int mask = 1; mask < (1<<m); mask++) {
for (int i = 0; i < m; i++) {
if (!((mask>>i)&1)) continue;
int mask1 = mask ^ (1<<i);
if (pf[mask1] == -1) continue;
int val = rem[mask1] + b[i];
int target = a[pf[mask1]];
if (val < target) {
pf[mask] = pf[mask1];
rem[mask] = val;
}
if (val == target) {
pf[mask] = pf[mask1] + 1;
rem[mask] = 0;
}
}
if (pf[mask] == n) {
cout << "YES";
return 0;
}
}
cout << "NO";
return 0 ^ 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... |