Submission #520605

#TimeUsernameProblemLanguageResultExecution timeMemory
520605thebitninjaBank (IZhO14_bank)C++14
100 / 100
130 ms8524 KiB
#include <iostream> #include <vector> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<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]; if(n > m){ cout << "NO\n"; return 0; } vector<pair<int,int>> dp(1<<m); dp[0] = {0, 0}; bool ok = false; for(int mask=0; mask<(1<<m) && !ok; mask++){ for(int i=0; i<m; i++){ if(mask & (1<<i)){ auto prev = dp[mask ^ (1<<i)]; if(prev.second + b[i] == a[prev.first]){ dp[mask] = max(dp[mask], make_pair(prev.first+1, 0)); } else if(prev.second + b[i] < a[prev.first]){ dp[mask] = max(dp[mask], make_pair(prev.first, prev.second + b[i])); } } } if(dp[mask].first == n) ok = true; } cout << (ok ? "YES\n" : "NO\n"); 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...