# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
16939 | erdemkiraz | Bank (IZhO14_bank) | C++98 | 121 ms | 4756 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 type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)
typedef long long ll;
typedef pair < int, int > ii;
const int inf = 1e9 + 333;
const ll linf = 1e18 + inf;
const int N = 20;
const int MAX = 1 << 20;
int n, m;
int a[N], b[N], dp[MAX];
int f(int mask, int x, int sum) {
if(x == n)
return 1;
int &r = dp[mask];
if(r != -1)
return r;
r = 0;
for(int i = 0; i < m; i++) {
if(!(mask & 1 << i) and sum + b[i] <= a[x]) {
if(sum + b[i] == a[x])
r |= f(mask | 1 << i, x + 1, 0);
else
r |= f(mask | 1 << i, x, sum + b[i]);
}
}
return r;
}
int main() {
scanf("%d %d", &n, &m);
for(int i = 0; i < n; i++)
scanf("%d", a + i);
for(int i = 0; i < m; i++)
scanf("%d", b + i);
memset(dp, -1, sizeof(dp));
if(f(0, 0, 0))
puts("YES");
else
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... |