This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 i = 1; i < 1005; i++) { for (int j = 0; j < m; j++) { if (i < b[m]) { continue; } if (dp[i - b[m]] == -1) { continue; } if (dp[i] == -1) { dp[i] = dp[i - b[m]] + 1; } else if (dp[i] > dp[i - b[m]] + 1) { dp[i] = dp[i - b[m]] + 1; } } } for (int i = 0; i < n; i++) { cout << dp[a[i]] << '\n'; }}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |