Submission #566167

#TimeUsernameProblemLanguageResultExecution timeMemory
566167LeonaRagingBank (IZhO14_bank)C++14
100 / 100
117 ms8532 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ll long long using namespace std; const ll mod = 1e9 + 7; const int N = 20; const int maxn = 1e5 + 4; const int INF = 1e9; int n, m, people[N], banknote[N], people_covered[1 << N], leftover[1 << N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen(".INP", "r", stdin); //freopen(".OUT", "w", stdout); cin >> n >> m; for (int i = 0; i < n; i++) cin >> people[i]; for (int i = 0; i < m; i++) cin >> banknote[i]; memset(people_covered, -1, sizeof people_covered); memset(leftover, -1, sizeof leftover); leftover[0] = people_covered[0] = 0; for (int s = 0; s < (1 << m); s++) { for (int last = 0; last < m; last++) { if ((s & (1 << last)) == 0) continue; int prev = s & ~(1 << last); if (people_covered[prev] == -1) continue; int new_salary = leftover[prev] + banknote[last]; int cur_salary = people[people_covered[prev]]; if (new_salary < cur_salary) { people_covered[s] = people_covered[prev]; leftover[s] = new_salary; } else if (new_salary == cur_salary) { people_covered[s] = people_covered[prev] + 1; leftover[s] = 0; } } if (people_covered[s] == n) { cout << "YES"; return 0; } } 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...