# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
421222 | antimirage | Bank (IZhO14_bank) | C++14 | 155 ms | 4488 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 fr first
#define sc second
#define mk make_pair
#define pb push_back
using namespace std;
int n, m, dp[(1 << 20) + 5], a[25], b[25];
int main (){
cin >> n >> m;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
a[i] += a[i - 1];
}
for (int i = 0; i < m; i++) {
scanf("%d", &b[i]);
}
memset(dp, -1, sizeof(dp));
dp[0] = 0;
for (int mask = 0; mask < (1 << m); mask++) {
if (dp[mask] == -1) continue;
if (dp[mask] == n) {
puts("YES");
return 0;
}
int sum = 0;
for (int j = 0; j < m; j++) {
if (mask & (1 << j))
sum += b[j];
}
for (int j = 0; j < m; j++) {
if (mask & (1 << j)) continue;
if (sum + b[j] < a[dp[mask] + 1]) {
dp[mask | (1 << j)] = dp[mask];
} else if (sum + b[j] == a[dp[mask] + 1]) {
dp[mask | (1 << j)] = dp[mask] + 1;
}
}
}
puts("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... |