제출 #344700

#제출 시각아이디문제언어결과실행 시간메모리
344700_zheksenov은행 (IZhO14_bank)C++14
71 / 100
1071 ms512 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) 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 (n == 1) { int x = a[0]; for (int ma = 1; ma <= (1 << m); ma++) { int sm = 0; for (int i = 0; i < m; i++) { if ((1 << i) & ma) { sm += b[i]; } } if (sm == x) { cout << "YES"; exit(false); } } cout << "NO"; exit(false); } 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...