Submission #331926

#TimeUsernameProblemLanguageResultExecution timeMemory
331926vitkishloh228Bank (IZhO14_bank)C++14
100 / 100
110 ms8696 KiB
#include<iostream> #include<algorithm> #include<vector> using namespace std; int main() { int n, m; cin >> n >> m; int a[25]; int b[25]; for (int i = 0; i < n; ++i) { cin >> a[i + 1]; } for (int i = 0; i < m; ++i) { cin >> b[i]; } vector<pair<int,int>> dp((1 << m)); for (int mask = 0; mask < (1 << m); ++mask) { if (dp[mask].first == 0 && dp[mask].second == 0 && mask > 0) continue; for (int i = 0; i < m; ++i) { if ((mask & (1 << i))) continue; int ost = a[dp[mask].first + 1] - dp[mask].second; if (ost < b[i]) continue; if (ost == b[i]) { dp[(mask | (1 << i))].first = dp[mask].first + 1; dp[(mask | (1 << i))].second = 0; } else { dp[(mask | (1 << i))] = dp[mask]; dp[(mask | (1 << i))].second += b[i]; } } } for (auto elem : dp) { if (elem.first == n) { cout << "YES"; 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...