# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
593454 | tht2005 | Bank (IZhO14_bank) | C++17 | 85 ms | 5544 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;
#define N 20
int a[N + 1], b[N], s[1 << N];
bool f[1 << N];
int main() {
int n, m;
scanf("%d %d", &n, &m);
a[0] = 0;
for(int i = 1; i <= n; ++i) {
scanf("%d", a + i);
a[i] += a[i - 1];
}
s[0] = 0;
for(int i = 0; i < m; ++i) {
scanf("%d", b + i);
s[1 << i] = b[i];
}
f[0] = 1;
for(int t = 0, w; t < 1 << m; ++t) {
w = t & (t - 1);
if(w) {
s[t] = s[w] + s[t ^ w];
}
if(!f[t]) {
continue;
}
int x = upper_bound(a, a + 1 + n, s[t]) - a - 1, cur = s[t];
for(int i = 0; i < m; ++i) {
if((t >> i & 1) || cur + b[i] > a[x + 1]) {
continue;
}
if(x + 1 == n && cur + b[i] == a[x + 1]) {
puts("YES");
return 0;
}
f[t | (1 << i)] = 1;
}
}
puts("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... |