Submission #1101857

#TimeUsernameProblemLanguageResultExecution timeMemory
1101857vjudge1Bank (IZhO14_bank)C++17
19 / 100
78 ms16892 KiB
#include <bits/stdc++.h> // #define int long long #define ll long long #define f first #define s second #define LSOne(s) ((s) & -(s)) using namespace std; typedef pair<int, int> pii; typedef tuple<int, int, int> iii; int mod = 1e9 + 7; const int mx9 = 1e9 + 1; const int mx6 = 1e6 + 1; const int maxn = 21; const int maxc = 1002; vector<pii> dp((1 << maxn), {0, 0}); vector<int> salaries(maxn), banknotes(maxn); int n, m; void solve() { cin >> n >> m; bool ans = false; for (int x = 0; x < n; x++) { cin >> salaries[x]; } for (int y = 0; y < m; y++) { cin >> banknotes[y]; } for (int mask = 0; mask < (1 << m); mask++) { if (ans) break; for (int pos = 0; pos < m; pos++) { if ((mask & (1 << pos)) >= 1) continue; int idx = dp[mask].s; int currentval = dp[mask].f; // cout << currentval << " " << idx << " " << pos << " " << mask << "\n"; if (idx < n) { if (currentval + banknotes[pos] == salaries[idx]) { idx++; currentval = 0; dp[mask | (1 << pos)] = max(dp[mask | (1 << pos)], make_pair(currentval, idx)); if (idx == n) { ans = true; break; } } else if(currentval + banknotes[pos] < salaries[idx]) { currentval += banknotes[pos]; dp[mask | (1 << pos)] = max(dp[mask | (1 << pos)], make_pair(currentval, idx)); } } } } ans ? cout << "YES" : cout << "NO"; } signed main() { // freopen("movie.in", "r", stdin); // freopen("movie.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) { solve(); } 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...