Submission #393383

#TimeUsernameProblemLanguageResultExecution timeMemory
393383vanicBank (IZhO14_bank)C++14
100 / 100
175 ms4428 KiB
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const int maxn=20; int a[maxn]; int b[maxn]; int dp[(1<<maxn)]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for(int i=0; i<n; i++){ cin >> a[i]; if(i){ a[i]+=a[i-1]; } } for(int i=0; i<m; i++){ cin >> b[i]; } int sum; for(int i=1; i<(1<<m); i++){ sum=0; for(int j=0; j<m; j++){ if((1<<j)&i){ sum+=b[j]; } } for(int j=0; j<m; j++){ if((1<<j)&i){ if(a[dp[i^(1<<j)]]==sum){ dp[i]=max(dp[i], dp[i^(1<<j)]+1); } dp[i]=max(dp[i], dp[i^(1<<j)]); } } if(dp[i]==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...