Submission #1102190

#TimeUsernameProblemLanguageResultExecution timeMemory
1102190A_M_NamdarBank (IZhO14_bank)C++14
19 / 100
70 ms8860 KiB
#include <bits/stdc++.h> using namespace std; const int N = 25, M = (1 << 21);; int n, m, a[N], b[N], sum[M], dp[2][M]; void input() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; } void solve() { for (int i = 1; i < (1 << m); i++) for (int j = 0; ; j++) if ((i >> j) & 1) { sum[i] = sum[i - (1 << j)] + b[j]; break; } int s = 0; int maxi = 0; for (int i = 0; i < n; i++) { s += a[i]; for (int j = 0; j < (1 << m); j++) { for (int k = 0; k < m; k++) if ((j >> k) & 1) dp[i & 1][j] = max(dp[i & 1][j], dp[(i + 1) & 1][j - (1 << k)]); if (sum[j] == s) dp[i & 1][j]++; maxi = max(maxi, dp[i & 1][j]); } } if (maxi == n) cout << "YES"; else cout << "NO"; } int main() { ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0); input(); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...