Submission #518816

#TimeUsernameProblemLanguageResultExecution timeMemory
518816DragosC1Bank (IZhO14_bank)C++17
19 / 100
91 ms8480 KiB
#include <iostream> using namespace std; int n, m; int a[21]; int b[21]; int dp[(1 << 20)]; int sum[(1 << 20)]; bool ok; void read() { int i; cin >> n >> m; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < m; i++) cin >> b[i]; } void solve() { int i, j; dp[0] = 0; for (i = 0; i < (1 << m) && !ok; i++) { for (j = 0; j < m && !ok; j++) { if (i & (1 << j)) continue; if (sum[i] + b[j] < a[dp[i]] && (dp[i] > dp[i | (1 << j)] || sum[i] + b[j] > sum[i | (1 << j)])) { sum[i | (1 << j)] = sum[i] + b[j]; dp[i | (1 << j)] = dp[i]; } else if (sum[i] + b[j] == a[dp[i]] && (dp[i] + 1 > dp[i | (1 << j)] || sum[i] + b[j] > sum[i | (1 << j)])) { dp[i | (1 << j)] = dp[i] + 1; if (dp[i | (1 << j)] == n) ok = 1; sum[i | (1 << j)] = 0; } } } } void output() { cout << (ok == 1 ? "YES\n" : "NO\n"); } int main() { read(); solve(); output(); 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...