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;
void solve()
{
int n;
int m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int j = 0; j < m; j++)
cin >> b[j];
bool possible = 0;
vector<pair<int, int>> dp(1 << m, pair(-1, 0));
dp[0] = pair(0, 0);
for (int mask = 0; mask < 1 << m && !possible; mask++)
{
for (int j = 0; j < m; j++)
{
if ((mask >> j) & 1)
{
auto tr = dp[mask ^ (1 << j)];
if (tr.first != -1)
{
if (tr.second + b[j] == a[tr.first])
tr.first++, tr.second = 0;
else if (tr.second + b[j] < a[tr.first])
tr.second += b[j];
else
tr.first = -1, tr.second = 0;
dp[mask] = max(dp[mask], tr);
}
}
}
possible |= dp[mask].first == n;
}
cout << (possible ? "YES" : "NO") << '\n';
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
solve();
return 0;
}
# | 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... |