Submission #362760

#TimeUsernameProblemLanguageResultExecution timeMemory
362760ritul_kr_singhBank (IZhO14_bank)C++17
100 / 100
191 ms4608 KiB
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; int a[n+1], b[m]; a[0] = 0; for(int i=1; i<=n; ++i){ cin >> a[i]; a[i] += a[i-1]; } for(int& i : b) cin >> i; int lim = (1<<m); int dp[lim]; // dp[i] -> max index(a) to which it's possible to distribute notes in mask for(int& i : dp) i = 0; int ok = 0; for(int i=0; i<lim; ++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)){ if(a[dp[i-(1<<j)]+1]==sum){ dp[i] = max(dp[i], dp[i-(1<<j)]+1); } dp[i] = max(dp[i], dp[i-(1<<j)]); } } ok |= dp[i]==n; } cout << (ok ? "YES\n" : "NO\n"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...