Submission #518809

#TimeUsernameProblemLanguageResultExecution timeMemory
518809DragosC1Bank (IZhO14_bank)C++17
0 / 100
1 ms212 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, add; 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]]) { 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 << 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; }

Compilation message (stderr)

bank.cpp: In function 'void solve()':
bank.cpp:24:15: warning: unused variable 'add' [-Wunused-variable]
   24 |     int i, j, add;
      |               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...