Submission #486987

#TimeUsernameProblemLanguageResultExecution timeMemory
486987studyBank (IZhO14_bank)C++17
100 / 100
94 ms8632 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 20, MASK = 1<<20; int person[MAX_N],bank[MAX_N],max_people[MASK],leftover[MASK]; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n,m; cin >> n >> m; for (int i=0; i<n; ++i){ cin >> person[i]; } for (int i=0; i<m; ++i){ cin >> bank[i]; } memset(max_people,-1,sizeof(max_people)); max_people[0] = 0; for (int mask=0; mask<(1<<m); ++mask){ if (max_people[mask] == n){ cout << "YES"; return 0; } if (max_people[mask] != -1){ for (int banki=0; banki<m; ++banki){ if (!(mask&(1<<banki))){ if (leftover[mask]+bank[banki] == person[max_people[mask]]){ leftover[mask+(1<<banki)] = 0; max_people[mask+(1<<banki)] = max_people[mask]+1; } else if (leftover[mask]+bank[banki] < person[max_people[mask]]){ leftover[mask+(1<<banki)] = leftover[mask]+bank[banki]; max_people[mask+(1<<banki)] = max_people[mask]; } } } } } cout << "NO"; 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...