Submission #935980

#TimeUsernameProblemLanguageResultExecution timeMemory
935980Youssif_ElkadiBank (IZhO14_bank)C++17
52 / 100
1100 ms25320 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const long long N = 1e3 + 5, inf = 1e9, mod = 1e9 + 7; long long n, m; long long dp[21][(1 << 21)]; vector<long long> 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<long long> people(n), cash(m); for (long long i = 0; i < n; i++) cin >> people[i]; for (long long i = 0; i < m; i++) cin >> cash[i]; for (long long i = 0; i < (1LL << m); i++) { long long sum = 0; for (long long j = 0; j < m; j++) if (i & (1LL << j)) sum += cash[j]; if (sum <= 1000) musks[sum].push_back(i); dp[n][i] = 1; } for (long long i = n - 1; i >= 0; i--) for (long long j = 0; j < (1LL << m); j++) for (auto &v : musks[people[i]]) if ((j & v) == 0) dp[i][j] |= dp[i + 1][j | v]; cout << (dp[0][0] ? "YES\n" : "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...