Submission #960795

#TimeUsernameProblemLanguageResultExecution timeMemory
960795okkooBank (IZhO14_bank)C++17
100 / 100
112 ms8796 KiB
#include <iostream> #include <vector> using namespace std; #define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int main(){ fastIO; int n, m; cin >> n >> m; int a[n], b[m]; for(int i=0; i<n; i++) cin >> a[i]; for(int i=0; i<m; i++) cin >> b[i]; vector<int> peopleCovered((1<<m), -1); vector<int> moneyLeft((1<<m), -1); peopleCovered[0] = 0; moneyLeft[0] = 0; for(int mask = 0; mask<(1<<m); mask++){ for(int i=0; i<m; i++){ if(mask&(1<<i)){ int prevMask = mask & ~(1<<i); if(peopleCovered[prevMask]==-1) continue; int newMoney = moneyLeft[prevMask] + b[i]; int curTarget = a[peopleCovered[prevMask]]; if(newMoney < curTarget){ peopleCovered[mask] = peopleCovered[prevMask]; moneyLeft[mask] = newMoney; } else if(newMoney == curTarget){ peopleCovered[mask] = peopleCovered[prevMask] + 1; moneyLeft[mask] = 0; } } } if(peopleCovered[mask]==n){ cout << "YES" << '\n'; return 0; } } cout << "NO" << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...