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>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
const int MXN = 20;
int n, m, sz;
vector<int> sal(MXN), nts(MXN);
bool solve()
{
vector<int> lft(sz, 0), dp(sz, 0);
for (int i = 0; i < n; i++) cin >> sal[i];
for (int i = 0; i < m; i++) cin >> nts[i];
for (int msk = 1; msk < sz; msk++) for (int bit = 0; bit < m; bit++) if (msk & (1 << bit)) if (dp[msk ^ (1 << bit)] >= dp[msk])
{
dp[msk] = dp[msk ^ (1 << bit)];
lft[msk] = lft[msk ^ (1 << bit)] + nts[bit];
if (lft[msk] == sal[dp[msk]])
{
lft[msk] = 0;
dp[msk]++;
if (dp[msk] == n) return true;
}
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
sz = 1 << m;
cout << (solve() ? "YES" : "NO");
}
# | 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... |