Submission #794635

#TimeUsernameProblemLanguageResultExecution timeMemory
794635nguyenneheheBank (IZhO14_bank)C++14
19 / 100
1076 ms316 KiB
#include<bits/stdc++.h> using namespace std; const int N = 20; int n, m, a[N], b[N]; int groups[N], v[N]; bool good; void sub1() { bool ok = false; for (int s = 1; s < (1 << m); ++s) { int sum = 0; for (int i = 0; i < m; ++i) { if (s >> i & 1) sum += b[i]; } ok |= sum == a[0]; } cout << (ok ? "YES" : "NO"); } void backtrack(int id) { if (id == m) { fill(v, v + n, 0); for (int i = 0; i < m; ++i) { v[groups[i]] += b[i]; } bool ok = true; for (int i = 0; i < n; ++i) { ok &= a[i] == v[i]; } good |= ok; return; } for (int i = 0; i < n; ++i) { groups[id] = i; backtrack(id + 1); } } void sub2() { good = false; backtrack(0); cout << (good ? "YES" : "NO"); } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < m; ++i) cin >> b[i]; if (n == 1) sub1(); else if (n <= 10 && m <= 10) sub2(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...