제출 #978289

#제출 시각아이디문제언어결과실행 시간메모리
978289KasymK은행 (IZhO14_bank)C++17
100 / 100
101 ms8792 KiB
#include "bits/stdc++.h" using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> a(n), b(m); for(int &i : a) cin >> i; for(int &i : b) cin >> i; vector<int> dp(1 << m, -1), dp2(1 << m, -1); dp[0] = 0, dp2[0] = 0; for(int mk = 0; mk < (1 << m); ++mk){ for(int i = 0; i < m; ++i) if(mk >> i & 1){ int ad = mk & ~(1 << i); if(~dp2[ad]){ int new_ad = dp[ad] + b[i]; int new_ad2 = a[dp2[ad]]; if(new_ad < new_ad2) dp2[mk] = dp2[ad], dp[mk] = new_ad; else if(new_ad == new_ad2) dp2[mk] = dp2[ad] + 1, dp[mk] = 0; } } if(dp2[mk] == n){ cout << "YES" << "\n"; return 0; } } cout << "NO" << "\n"; 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...