제출 #796974

#제출 시각아이디문제언어결과실행 시간메모리
796974Github은행 (IZhO14_bank)C++14
100 / 100
104 ms8516 KiB
#include <iostream> #include <vector> #include <set> #include <map> #include <climits> #include <algorithm> using namespace std; #define speedup ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define ll long long const int MOD = 1e9+7; int main(){ speedup 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]; } pair<int, int> dp[1<<m]; dp[0] = {0, 0}; for (int i = 1; i < (1<<m); i++){ dp[i] = {-1, -1}; for (int j = 0; j < m; j++){ if (i&(1<<j)){ int new_state = i^(1<<j); if (dp[new_state] == make_pair(-1, -1)){ continue; } int left_over = dp[new_state].second+b[j]; int required = a[dp[new_state].first]; if (left_over < required){ if (dp[i].first < dp[new_state].first){ dp[i] = {dp[new_state].first, left_over}; } }else if (left_over == required){ dp[i] = {dp[new_state].first+1, 0}; } } } if (dp[i].first == n){ cout << "YES" << endl; return 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...