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 <bits/stdc++.h>
using namespace std;
bool dp[21][1001];
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m), ok(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
dp[0][0] = 1;
for (int i = 0; i < m; i++)
for (int j = 0; j <= 1000; j++) {
if (j + b[i] <= 1000)
dp[i + 1][j + b[i]] |= dp[i][j];
dp[i + 1][j] |= dp[i][j];
}
for (int i = 0; i < n; i++)
for (int j = 0; j <= m; j++)
if (dp[j][a[i]])
ok[i] = 1;
for (int i = 0; i < n; i++)
if (!ok[i]) {
cout << "NO";
return 0;
}
cout << "YES";
}
# | 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... |