Submission #518813

#TimeUsernameProblemLanguageResultExecution timeMemory
518813DragosC1Bank (IZhO14_bank)C++17
0 / 100
1 ms204 KiB
#include <fstream> #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; ifstream f("bank.in"); f >> n >> m; for (i = 0; i < n; i++) f >> a[i]; for (i = 0; i < m; i++) f >> b[i]; f.close(); } 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() { ofstream g("bank.out"); g << (ok == 1 ? "YES\n" : "NO\n"); g.close(); } 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...