Submission #344566

#TimeUsernameProblemLanguageResultExecution timeMemory
344566_zheksenovBank (IZhO14_bank)C++14
52 / 100
1094 ms384 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 21; const int M = 1e3 + 7; int n, m; int a[N], b[N]; int cnt[M]; bool rock(int x) { if(x == n) return 1; if (!a[x]) return rock(x + 1); for (int i = a[x]; i > 0; i--) { if (cnt[i]) { cnt[i]--; a[x] -= i; if (rock(x) == 1) return 1; a[x] += i; cnt[i]++; } } return 0; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) { cin >> b[i]; cnt[b[i]]++; } if (rock(0) == 1) { cout << "YES" << "\n"; } else { cout << "NO" << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...