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;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
using i64 = long long;
const int N = 1022;
int dp[N][N];
// can make sum j from i
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int &i : a)
cin >> i;
for (int &i : b)
cin >> i;
dp[0][0] = 1;
for (int i = 1; i <= m; i++) {
for (int j = 1000; j >= a[i - 1]; j--) {
if (dp[i - 1][j - a[i - 1]]) {
dp[i][j] = 1;
}
}
}
for (int j : a) {
bool ok = 0;
for (int i = 1; i <= m; i++) {
if (dp[i][j])
ok = 1;
}
if (!ok) {
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int TC = 1;
// cin >> TC;
while (TC--) {
solve();
}
}
# | 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... |