제출 #320265

#제출 시각아이디문제언어결과실행 시간메모리
320265vkgainz은행 (IZhO14_bank)C++17
100 / 100
183 ms10200 KiB
#include <bits/stdc++.h> using namespace std; pair<int,int> dp[1<<20]; int main() { 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]; for(int msk=0;msk<1<<m;msk++) { for(int last=0;last<m;last++) { if((msk&(1<<last))==0) continue; if(b[last]+dp[msk^(1<<last)].second==a[dp[msk^(1<<last)].first]) dp[msk] = {dp[msk^(1<<last)].first+1,0}; else dp[msk] = max(dp[msk], {dp[msk^(1<<last)].first, b[last]+dp[msk^(1<<last)].second}); if(dp[msk].first==n) { cout << "YES" << endl; return 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...