제출 #935966

#제출 시각아이디문제언어결과실행 시간메모리
935966Youssif_Elkadi은행 (IZhO14_bank)C++17
52 / 100
1099 ms25180 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e3 + 5, inf = 1e9, mod = 1e9 + 7; int n, m; int dp[25][(1 << 22)]; vector<int> musks[N]; int main() { ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cin >> n >> m; vector<int> people(n), cash(m); for (int i = 0; i < n; i++) cin >> people[i]; for (int i = 0; i < m; i++) cin >> cash[i]; for (int i = 0; i < (1 << m); i++) { int sum = 0; for (int j = 0; j < m; j++) if (i & (1 << j)) sum += cash[m - j - 1]; if (sum <= 1000) musks[sum].push_back(i); dp[n][i] = 1; } for (int i = n - 1; i >= 0; i--) for (int j = 0; j < (1 << m); j++) for (auto &v : musks[people[i]]) if ((j & v) == 0) dp[i][j] |= dp[i + 1][(j | v)]; for (int i = 0; i < (1 << m); i++) if (dp[0][i]) return cout << "YES\n", 0; cout << "NO\n"; } /* YES */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...