제출 #999670

#제출 시각아이디문제언어결과실행 시간메모리
999670a5a7은행 (IZhO14_bank)C++14
71 / 100
75 ms8640 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template <class T> using indexedset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long ll; pair<int, int> dp[1<<20]; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; int a[n]; int b[m]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; for (int i = 0; i < (1<<m); i++){ dp[i] = {-1, 0}; } dp[0].first = 0; for (int i = 0; i < (1<<m); i++){ for (int j = 0; j < m; j++){ if (dp[i].first == n){ cout << "YES" << endl; return 0; } if (i&(1<<j)) continue; if (dp[i^(1<<j)].first != -1) continue; if ((dp[i].second+b[j]) <= a[dp[i].first]){ dp[i^(1<<j)].first = dp[i].first; dp[i^(1<<j)].second = dp[i].second+b[j]; if (dp[i^(1<<j)].second == a[dp[i].first]){ dp[i^(1<<j)].first++; dp[i^(1<<j)].second = 0; } } } } cout << "NO" << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...