Submission #1131504

#TimeUsernameProblemLanguageResultExecution timeMemory
1131504ahmedsahlolBank (IZhO14_bank)C++20
0 / 100
71 ms164420 KiB
#include <bits/stdc++.h>

#define int long long

#define el '\n'

using namespace std;

const int N = 20;

int n, m, a[N], b[N], dp[N][1LL << N];

int solve(int i, int mask, int sum_now) {
    if (i == n) return 1;
    int &ret = dp[i][mask];
    if (~ret) return ret;
    ret = 0;
    for (int j = 0; j < m; ++j) {
        if ((mask >> j) & 1) continue;
        if (sum_now + b[j] <= a[i]) {
            if (a[i] == sum_now + b[j]) ret |= solve(i + 1, mask | (1LL << j), 0);
            else ret |= solve(i, mask | (1LL << j), sum_now + b[j]);
        }
    }
    return ret;
}

void work() {
    cin >> n >> m;
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < n; ++i)cin >> a[i];
    for (int i = 0; i < m; ++i)cin >> b[i];
    cout << (solve(0, 0, 0) ? "YES" : "NO") << el;
}

int32_t main() {
    freopen("bank.in", "r", stdin);
    freopen("bank.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc = 1;
//    cin >> tc;
    while (tc--) {
        work();
    }
}

Compilation message (stderr)

bank.cpp: In function 'int32_t main()':
bank.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("bank.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen("bank.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...