Submission #644058

#TimeUsernameProblemLanguageResultExecution timeMemory
644058HaYoungJoonBank (IZhO14_bank)C++14
100 / 100
104 ms8516 KiB
#include <iostream> using namespace std; const int maxn = 20; typedef pair<int,int> pii; int a[maxn], b[maxn], n, m; pii dp[1 << maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; dp[0] = pii(0,0); for (int mask = 1; mask < (1 << m); mask++) { dp[mask] = pii(-1,-1); for (int i = 0; i < m; i++) if ((mask & (1 << i)) && dp[mask ^ (1 << i)].first != -1) { int last = dp[mask ^ (1 << i)].second + b[i], target = dp[mask ^ (1 << i)].first; if (last == a[target]) { dp[mask] = pii(target+1,0); } else if (last < a[target]) dp[mask] = pii(target,last); } if (dp[mask].first == 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...