# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1025411 | ef10 | Bank (IZhO14_bank) | C++17 | 1061 ms | 8616 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.
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int N,M;
int A[21];
int B[21];
int dp[1<<20][2];
int main() {
cin >> N >> M;
for (int i = 1; i <= N; i++) {
cin >> A[i];
}
for (int i = 0; i < M; i++) {
cin >> B[i];
}
for (int i = 0; i < (1<<M); i++) {
for (int j = 0; j <= 1; j++) {
dp[i][j] = -1;
}
}
dp[0][0] = 0;
for (int i = 0; i < (1<<M); i++) {
dp[i][0]=0;
for (int k = 0; k < M; k++) {
if (i&(1<<k)) {
dp[i][0] += B[k];
}
}
if (dp[i][0] > A[1]) {
dp[i][0] = -1;
}
}
int ind;
for (int i = 1; i <= N; i++) {
ind = i % 2;
int oi = (i+1) % 2;
for (int j = 0; j < (1 << M); j++) {
for (int k = 0; k < M; k++) {
if (!(j&(1<<k))) continue;
if (i < N && dp[j&~(1<<k)][ind] >= 0 && dp[j&~(1<<k)][ind] + B[k] < A[i+1]) {
dp[j][ind] = dp[j&~(1<<k)][ind] + B[k];
}
if (dp[j&~(1<<k)][oi] < 0) continue;
if (dp[j&~(1<<k)][oi] + B[k] == A[i]) {
dp[j][ind] = 0;
}
}
}
for (int i = 0; i < (1<<M); i++) {
dp[i][oi] = -1;
}
}
for (int i = 0; i < (1<<M); i++) {
if (dp[i][ind] >= 0) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
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... |