#include <bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;
map<pair<int, int>, bool> mac;
int cimbom, gs;
vector<int> icardi;
vector<int> osimhen;
vector<int> gsPuan;
bool bul(int icardiIdx, int fener) {
if (icardiIdx == cimbom) return true;
if (mac.count({icardiIdx, fener})) return mac[{icardiIdx, fener}];
int kullanılmısDegil = ((1 << gs) - 1) ^ fener;
int hedef = icardi[icardiIdx];
for (int subMask = kullanılmısDegil; ; subMask = (subMask - 1) & kullanılmısDegil) {
if (gsPuan[subMask] == hedef) {
if (bul(icardiIdx + 1, fener | subMask)) {
return mac[{icardiIdx, fener}] = true;
}
}
if (subMask == 0) break;
}
return mac[{icardiIdx, fener}] = false;
}
void solve() {
if (scanf("%lld %lld", &cimbom, &gs) != 2) return;
icardi.assign(cimbom, 0);
for (int i = 0; i < cimbom; i++) scanf("%lld", &icardi[i]);
osimhen.assign(gs, 0);
for (int i = 0; i < gs; i++) scanf("%lld", &osimhen[i]);
gsPuan.assign(1 << gs, 0);
for (int mask = 0; mask < (1 << gs); mask++) {
for (int j = 0; j < gs; j++) {
if (mask & (1 << j)) {
gsPuan[mask] += osimhen[j];
}
}
}
if (bul(0, 0)) {
printf("YES\n");
} else {
printf("NO\n");
}
}
signed main() {
solve();
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'void solve()':
bank.cpp:42:43: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | for (int i = 0; i < cimbom; i++) scanf("%lld", &icardi[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
bank.cpp:45:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | for (int i = 0; i < gs; i++) scanf("%lld", &osimhen[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~| # | 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... |