Submission #1109966

#TimeUsernameProblemLanguageResultExecution timeMemory
1109966DON_FBank (IZhO14_bank)C++14
100 / 100
86 ms8784 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; #define all(x) x.begin(), x.end() #define L(i, b, e) for (int i = b; i < e; ++i) #define R(i, b, e) for (int i = b; i >= e; --i) #define pb emplace_back #define vi vector<int> #define sz(x) ((int) x.size()) int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vi a(n), b(m); L(i, 0, n)cin >> a[i]; L(i, 0, m)cin >> b[i]; vector<pair<int, int>> dp(1 << m, {-1, -1}); dp[0] = {0, 0}; L(i, 0, 1 << m){ L(j, 0, m){ if ((1 << j) & i || dp[i].first == -1)continue; if (dp[i].second < n && dp[i].first + b[j] <= a[dp[i].second]){ dp[i + (1 << j)] = {(dp[i].first + b[j] == a[dp[i].second] ? 0 : dp[i].first + b[j]), (dp[i].first + b[j] == a[dp[i].second] ? dp[i].second + 1 : dp[i].second)}; } } } int ans = 0; L(i, 0, 1 << m)if (dp[i].second == n)ans = 1; cout << (ans ? "YES\n" : "NO\n"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...