Submission #1025434

#TimeUsernameProblemLanguageResultExecution timeMemory
1025434ef10Bank (IZhO14_bank)C++17
71 / 100
1049 ms86608 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; int N,M; int A[21]; int B[21]; int dp[1<<20][21]; int main() { cin >> N >> M; for (int i = 1; i <= N; i++) { cin >> A[i]; } sort(A+1,A+N+1); for (int i = 0; i < M; i++) { cin >> B[i]; } sort(B,B+M); for (int i = 0; i < (1<<M); i++) { for (int j = 0; j <= N; j++) { dp[i][j] = -1; } } dp[0][0] = 0; for (int i = 0; i < (1<<M); i++) { dp[i][0]=0; for (int k = 0; k < M; k++) { if (i&(1<<k)) { dp[i][0] += B[k]; } } if (dp[i][0] > A[1]) { dp[i][0] = -1; } } for (int i = 1; i <= N; i++) { for (int j = 0; j < (1 << M); j++) { for (int k = 0; k < M; k++) { if (!(j&(1<<k))) continue; if (i < N && dp[j&~(1<<k)][i] >= 0) { dp[j][i] = dp[j&~(1<<k)][i] + B[k]; } if (dp[j&~(1<<k)][i-1] < 0) continue; if (dp[j&~(1<<k)][i-1] + B[k] == A[i]) { dp[j][i] = 0; } } } } for (int i = 0; i < (1<<M); i++) { if (dp[i][N] >= 0) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...