제출 #902400

#제출 시각아이디문제언어결과실행 시간메모리
9024000xZero은행 (IZhO14_bank)C++17
100 / 100
166 ms4596 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin>>n>>m; vector<int> a(n), b(m); int sa=0, sb=0; for(int i=0;i<n;i++)cin>>a[i], sa+=a[i]; for(int i=0;i<m;i++)cin>>b[i], sb+=b[i]; if(sa>sb)return cout<<"NO\n", 0; else if(sa<sb){ n++; a.push_back(sb-sa); } vector<int> pref(n+1, 0); for(int i=0;i<n;i++)pref[i+1]=pref[i]+a[i]; int dp[1<<m]={0}; for(int i=1;i<(1<<m);i++){ int sum=0; for(int j=0;j<m;j++)if(i&(1<<j))sum+=b[j]; for(int j=0;j<m;j++){ if(i&(1<<j)){ int p=dp[i^(1<<j)]; int s=pref[p]; if(sum-s==a[p])dp[i]=max(dp[i], p+1); else dp[i]=max(dp[i], p); } } } if(dp[(1<<m)-1]==n)cout<<"YES\n"; else 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...