Submission #1271231

#TimeUsernameProblemLanguageResultExecution timeMemory
1271231krzyskaBank (IZhO14_bank)C++20
19 / 100
75 ms8520 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int konta[n], bank[m], calosci[(1 << m)], reszty[(1 << m)]; for(int i = 0; i < n; i++){ cin >> konta[i]; } for(int i = 0; i < m; i++){ cin >> bank[i]; } for(int i = 0; i < (1 << m); i++){ calosci[i] = 0; reszty[i] = 0; } for(int i = 0; i < (1 << m); i++){ for(int j = 0; j < m; j++){ if(((1 << j)&i) == 0){ if(reszty[i] + bank[j] == konta[calosci[i]]){ calosci[i^(1 << j)] = calosci[i] + 1; reszty[i^(1 << j)] = 0; } if(reszty[i] + bank[j] < konta[calosci[i]]){ calosci[i^(1 << j)] = calosci[i]; reszty[i^(1 << j)] = reszty[i] + bank[j]; } if(calosci[i^(1 << j)] == n){ cout << "YES"; return 0; } } } } cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...