Submission #475421

#TimeUsernameProblemLanguageResultExecution timeMemory
475421dpw4112001Bank (IZhO14_bank)C++14
100 / 100
136 ms16844 KiB
#include<bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin >> n; int m; cin >>m; int sal[n]; int note[m]; for(int i=0;i<n;i++)cin >> sal[i]; for(int i=0;i<m;i++)cin >> note[i]; vector<int> covered((1<<m)+1,-1); vector<int> left((1<<m)+1,-1); covered[0] = 0; left[0] = 0; for(int i=0;i<(1<<m);i++) { for(int j=0;j<m;j++) { if(i & (1<<j)) { int prev = i ^ (1<<j); if(covered[prev] == -1) continue; int newamt = left[prev] + note[j]; int target = sal[covered[prev]]; if(newamt < target) { covered[i] = covered[prev]; left[i] = newamt; } else if(newamt == target) { covered[i] = covered[prev] + 1; left[i] = 0; } } } if(covered[i] == n) { cout << "YES\n"; 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...