제출 #1087432

#제출 시각아이디문제언어결과실행 시간메모리
1087432Staheos은행 (IZhO14_bank)C++14
0 / 100
1 ms348 KiB
#include <iostream> using namespace std; int main() { int n, m; cin >> n >> m; auto a = new int[n]; auto b = new int[m]; auto dp = new int[1005]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } for (int i = 1; i < 1005; i++) { dp[i] = -1; } dp[0] = 0; for (int j = 0; j < m; j++) { for (int i = 1004; i > 0; i--) { if (i < b[j]) { continue; } if (dp[i - b[j]] == -1) { continue; } if (dp[i] == -1) { dp[i] = dp[i - b[j]] + 1; } else if (dp[i] > dp[i - b[j]] + 1) { dp[i] = dp[i - b[j]] + 1; } } } for (int i = 0; i < 1000; i++) { cout << "DP[] " << i << ' ' << dp[i] << '\n'; } bool p = true; for (int i = 0; i < n; i++) { if (dp[a[i]] == -1) { p = false; break; } } if (p) { cout << "YES\n"; } else { cout << "NO\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...