제출 #344698

#제출 시각아이디문제언어결과실행 시간메모리
344698_zheksenov은행 (IZhO14_bank)C++14
52 / 100
1083 ms492 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 (n==1 && a[x] == 0) return 1; if (x == n && n != 1) 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]]++; } cout << (rock(0) == 1 ? "YES" : "NO"); 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...