# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1269472 | quangminh412 | Bank (IZhO14_bank) | C++17 | 100 ms | 16852 KiB |
/*
Ben Watson
Quang Minh MasterDDDDD
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const string name = "test";
void solve();
signed main()
{
if (fopen((name + ".inp").c_str(), "r"))
{
freopen((name + ".inp").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
return 0;
}
// main program
const int maxn = 21;
const int maxbit = (1 << maxn);
int cover[maxbit], leftover[maxbit];
int a[maxn], b[maxn];
int n, m;
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= m; i++)
cin >> b[i];
memset(cover, -1, sizeof(cover));
memset(leftover, -1, sizeof(leftover));
cover[0] = 0;
leftover[0] = 0;
for (int mask = 0; mask < (1 << m); mask++)
{
for (int i = 0; i < m; i++)
{
if (!(mask >> i & 1))
continue;
int prev = (mask ^ (1 << i));
if (cover[prev] == -1)
continue;
int new_leftover = leftover[prev] + b[i + 1];
int idx = cover[prev] + 1;
if (new_leftover < a[idx])
{
cover[mask] = cover[prev];
leftover[mask] = new_leftover;
} else
if (new_leftover == a[idx])
{
cover[mask] = idx;
leftover[mask] = 0;
}
}
if (cover[mask] == n)
{
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
Compilation message (stderr)
# | 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... |