Submission #320265

#TimeUsernameProblemLanguageResultExecution timeMemory
320265vkgainzBank (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...