Submission #469963

#TimeUsernameProblemLanguageResultExecution timeMemory
469963dooompyBank (IZhO14_bank)C++17
100 / 100
144 ms8516 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; pair<int, int> dp[1 << 21]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("", "r", stdin); // freopen("", "w", stdout); int n, m; cin >> n >> m; vector<int> people(n); for (int i = 0; i < n; i++) { cin >> people[i]; } vector<int> note(m); for (int i = 0; i < m; i++) { cin >> note[i]; } dp[0] = {0, 0}; for (int i = 1; i < (1 << m); i++) { dp[i] = {-1, -1}; for (int j = 0; j < m; j++) { if (i & (1 << j)) { int subset = i - (1 << j); auto prev = dp[subset]; prev.second += note[j]; if (prev.second == people[prev.first]) { prev.first++; prev.second = 0; } if (prev.first == n) { cout << "YES"; return 0; } dp[i] = max(dp[i], prev); } } } cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...