# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1279004 | lmquan | Bank (IZhO14_bank) | C++20 | 96 ms | 8652 KiB |
#define taskname ""
#include <bits/stdc++.h>
using namespace std;
int main() {
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
vector<int> x(1 << m, -1), y(1 << m, -1);
x[0] = y[0] = 0;
for (int i = 1; i < (1 << m); i++) {
for (int j = 0; j < m; j++) {
if ((i >> j & 1) && x[i ^ (1 << j)] != -1) {
int u = y[i ^ (1 << j)] + b[j], v = a[x[i ^ (1 << j)]];
if (u == v) {
x[i] = x[i ^ (1 << j)] + 1, y[i] = 0;
} else if (u < v) {
x[i] = x[i ^ (1 << j)], y[i] = u;
}
}
}
if (x[i] == n) {
cout << "YES";
return 0;
}
}
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... |