Submission #766525

#TimeUsernameProblemLanguageResultExecution timeMemory
766525dxz05Bank (IZhO14_bank)C++17
100 / 100
99 ms8544 KiB
#pragma GCC optimize("Ofast,O3,unroll-loops") #pragma GCC target("avx,avx2") #include <bits/stdc++.h> using namespace std; int main(){ 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]; vector<pair<int, int>> dp(1 << m, make_pair(-1, -1)); dp[0] = make_pair(0, 0); for (int mask = 0; mask < (1 << m); mask++){ if (dp[mask] == make_pair(-1, -1)) continue; if (dp[mask] == make_pair(n, 0)){ cout << "YES" << endl; return 0; } int j = dp[mask].first, has = dp[mask].second; if (j >= n) continue; for (int i = 0; i < m; i++){ if (mask & (1 << i)) continue; if (has + b[i] < a[j]){ dp[mask | (1 << i)] = max(dp[mask | (1 << i)], make_pair(j, has + b[i])); } else if (has + b[i] == a[j]){ dp[mask | (1 << i)] = max(dp[mask | (1 << i)], make_pair(j + 1, 0)); } } } cout << "NO" << endl; 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...