Submission #550216

#TimeUsernameProblemLanguageResultExecution timeMemory
550216JomnoiBank (IZhO14_bank)C++17
0 / 100
2 ms452 KiB
#include <bits/stdc++.h> #define DEBUG false using namespace std; const int MAX_N = 20; int a[MAX_N], b[MAX_N]; pair <int, int> dp[1<<MAX_N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, M; cin >> N >> M; for(int i = 0; i < N; i++) { cin >> a[i]; } for(int i = 0; i < M; i++) { cin >> b[i]; } for(int mask = 0; mask < (1<<M); mask++) { for(int i = 0; i < M; i++) { int prev = mask ^ (1<<i); auto [last, sum] = dp[prev]; if(sum + b[i] == a[last]) { dp[mask] = make_pair(last + 1, 0); } else { dp[mask] = max(dp[mask], make_pair(last, sum + b[i])); } } if(dp[mask].first == N) { cout << "YES"; return 0; } } cout << "NO"; 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...