Submission #1263737

#TimeUsernameProblemLanguageResultExecution timeMemory
1263737backBank (IZhO14_bank)C++20
71 / 100
1093 ms436 KiB
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> a, b; vector<int> used; bool ok = false; void dfs(int i) { if (i == n) { // phát đủ cho n người ok = true; return; } int need = a[i]; function<void(int,int)> tryGive = [&](int pos, int sum) { if (ok) return; if (sum > need) return; if (sum == need) { dfs(i+1); return; } for (int j = pos; j < m; j++) if (!used[j]) { used[j] = 1; tryGive(j+1, sum + b[j]); used[j] = 0; } }; tryGive(0, 0); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; a.resize(n); b.resize(m); for (int &x : a) cin >> x; for (int &x : b) cin >> x; used.assign(m, 0); dfs(0); cout << (ok ? "YES\n" : "NO\n"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...