Submission #899822

#TimeUsernameProblemLanguageResultExecution timeMemory
899822pete555Bank (IZhO14_bank)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int ppl[n], bank[m]; for(int i=0; i<n; i++) cin >> ppl[i]; for(int i=0; i<m; i++) cin >> bank[i]; vector<int> covered(1<<m, -1); vector<int> leftover(1<<m, -1); covered[0] = 0; leftover[0] = 0; for(int mask=1; mask<(1<<m); mask++){ for(int i=0; i<m; i++){ if((mask&(1<<i)) == 0) continue; int prev = mask^(1<<i); if(covered[prev] == -1) continue; int amt = leftover[prev] + bank[i]; int target = ppl[covered[prev]]; if(amt < target){ covered[mask] = covered[prev]; leftover[mask] = amt; }else if(amt == target){ covered[mask] = covered[prev] + 1; leftover[mask] = 0; } } // if(covered[mask] == n){ // cout << "YES"; // return 0; // } } for(int i=0; i<(1<<n); i++){ if(covered[i] == n){ cout << "YES"; return 0; } } 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...