Submission #1001410

#TimeUsernameProblemLanguageResultExecution timeMemory
1001410toan2602Bank (IZhO14_bank)C++14
100 / 100
88 ms16996 KiB
#include<bits/stdc++.h> using namespace std; #define int long long void solve() { int n, m; cin >> n >> m; vector<int> a(n+1), b(m); vector<bool> mark(1<<m); vector<pair<int, int>> dp(1<<m, {0,0}); mark[0] = true; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; for (int mask = 0; mask < (1<<m); mask++) { for (int j = 0; j < m; j++) { if(mask >> j & 1) { int mask2 = mask ^ (1 << j); if(!mark[mask2]) continue; int sum = dp[mask2].second; sum += b[j]; if(sum == a[dp[mask2].first + 1]) dp[mask] = {dp[mask2].first+1, 0}, mark[mask] = true; else if(sum < a[dp[mask2].first+1]) dp[mask] = {dp[mask2].first, sum}, mark[mask] = true; } } if(dp[mask].first == n) {cout << "YES\n"; return;} } cout << "NO"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while(t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...