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;
typedef long long ll;
typedef unsigned int uint;
int n, m, a[20], b[20];
pair<int, int> dp[1 << 20];
// dp[mask] = {number of people paid with these notes, auxiliary coins left over}.
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
dp[0] = {0, 0};
for (uint mask = 1; mask < (1 << m); mask++)
{
dp[mask] = {0, 0};
for (int i = 0; i < m; i++)
if (mask & (1 << i))
dp[mask].second += b[i];
for (int i = 0; i < m; i++)
if (mask & (1 << i))
{
auto [num, aux] = dp[mask ^ (1 << i)];
dp[mask] = max(dp[mask], make_pair(num + (aux + b[i] == a[num]), (aux + b[i]) * (aux + b[i] != a[num])));
}
if (dp[mask].first == n)
return cout << "YES\n", 0;
}
cout << "NO\n";
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:21:30: warning: comparison of integer expressions of different signedness: 'uint' {aka 'unsigned int'} and 'int' [-Wsign-compare]
21 | for (uint mask = 1; mask < (1 << m); mask++)
| ~~~~~^~~~~~~~~~
# | 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... |