Submission #348947

#TimeUsernameProblemLanguageResultExecution timeMemory
3489478e7Bank (IZhO14_bank)C++14
100 / 100
358 ms98924 KiB
//Challenge: Accepted #include <iostream> #include <algorithm> #include <utility> #include <set> #define maxn 20 #define pii pair<int, int> #define ff first #define ss second using namespace std; set<pii> dp[1<<maxn]; int a[maxn], b[maxn]; int main() { int n, m; cin >> n >> m; for (int i = 0;i < n;i++) cin >> a[i]; for (int j = 0;j < m;j++) cin >> b[j]; dp[0].insert(make_pair(0, 0)); int poss = 0; for (int i = 1;i < (1<<m);i++) { for (int j = 0;j < m;j++) { if (i & (1<<j)) { for (auto v: dp[i - (1<<j)]) { if (v.ss + b[j] == a[v.ff]) { dp[i].insert(make_pair(v.ff + 1, 0)); } else if (v.ss + b[j] < a[v.ff]) { dp[i].insert(make_pair(v.ff, v.ss + b[j])); } } } } for (auto j:dp[i]) { if (j.ff == n) { poss = 1; break; } } } cout << (poss ? "YES" : "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...