Submission #1007469

#TimeUsernameProblemLanguageResultExecution timeMemory
1007469Seyyed_Mojtaba_MortazaviBank (IZhO14_bank)C++17
100 / 100
72 ms4496 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int MAXN = 1e3; int dp[(1 << 20)]; int a[MAXN]; int b[MAXN]; int pf[MAXN]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; pf[i] = pf[i - 1] + a[i]; } for (int i = 0; i < m; i++) cin >> b[i]; for (int mask = 1; mask < (1 << m); mask++) { int mx = 0, sum = 0; for (int i = 0; i < m; i++) { if ((mask >> i) & 1) { mx = max(mx, dp[mask - (1 << i)]); sum += b[i]; } } if (sum == pf[mx+1]) { dp[mask] = mx + 1; } else { dp[mask] = mx; } } if (dp[(1 << m)-1] == n) cout << "YES" << endl; else 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...