제출 #340570

#제출 시각아이디문제언어결과실행 시간메모리
340570Sprdalo은행 (IZhO14_bank)C++98
100 / 100
228 ms512 KiB
#include <bits/stdc++.h> using namespace std; int a[21], b[21]; int n, m; void ye(){ cout << "YES\n"; exit(0); } void solve(int x, int suma, int mask, int j){ if (x>n) ye(); if (!suma){ solve(x+1,a[x+1], mask,0); return; } int cnt = __builtin_popcount(mask); if (m-cnt-1 < n-x) return; for (int i = j; i < m; ++i){ if (m-cnt-1 < x-n) break; if ((mask&(1 << i)) || b[i] > suma) continue; solve(x, suma-b[i], mask^(1<<i),i+1); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 0; i < m; ++i) cin >> b[i]; solve(1, a[1], 0, 0); cout << "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...