# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676900 | omikron123 | Bank (IZhO14_bank) | C++14 | 789 ms | 4420 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.
// https://oj.uz/problem/view/IZhO14_bank
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;
// 按顺序给a[1]...a[n]发钱
// dp[bm]: bm是哪些note用了,是否状态是合法的
int n, m;
int a[25], B[25];
int dp[1<<20];
ll psum[25];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
psum[i+1] = psum[i] + a[i];
}
for (int i = 0; i < m; i++)
scanf("%d", &B[i]);
dp[0] = 1;
for (int bm = 1; bm < (1<<m); bm++) {
for (int i = 0; i < m; i++) {
int b = 1 << i;
if ((bm & b) && dp[bm ^ b]) {
ll sum = 0;
for (int j = 0; j < m; j++)
if ((bm ^ b) & (1 << j)) sum += B[j];
auto it = upper_bound(psum, psum+n+1, sum);
if (sum + B[i] <= *it) {
dp[bm] = 1;
if (sum + B[i] == psum[n]) {
printf("YES");
return 0;
}
continue;
}
}
}
}
printf("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... |