# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
258833 | karma | Bank (IZhO14_bank) | C++14 | 82 ms | 8572 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>
#define pb emplace_back
#define ll long long
#define fi first
#define se second
#define mp make_pair
//#define int int64_t
using namespace std;
const int N = 1 << 20 | 1;
const int inf = 1e9 + 1;
typedef pair<int, int> pii;
pii f[N];
int n, m, a[30], b[30];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define Task "test"
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n >> m; a[n] = inf;
for(int i = 0; i < n; ++i) cin >> a[i];
for(int i = 0; i < m; ++i) cin >> b[i];
f[0] = {0, 0};
for(int i = 0; i < (1 << m); ++i) {
if(f[i].fi >= n && f[i].se == 0) return cout << "YES", 0;
for(int j = 0; j < m; ++j) {
if(i >> j & 1) continue;
if(f[i].se + b[j] > a[f[i].fi]) continue;
if(f[i].se + b[j] == a[f[i].fi]) {
f[i ^ (1 << j)] = {f[i].fi + 1, 0};
continue;
}
f[i ^ (1 << j)] = {f[i].fi, f[i].se + b[j]};
}
}
cout << "NO";
}
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... |