# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1098386 | vjudge1 | Bank (IZhO14_bank) | C++17 | 0 ms | 0 KiB |
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;
int main()
{
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for(auto &i : a)
{
cin >> i;
}
for(auto &i : b)
{
cin >> i;
}
vector<int> l(1 << m, -1), r(1 << m, -1);
l[0] = r[0] = 0;
for(int i = 0; i < (1 << m); i++)
{
for(int j = 0; j < m; j++)
{
int k = i ^ (1 << j);
if(!(i & (1 << j)) || r[k] == -1)
{
continue;
}
int new = l[k] + b[j];
int cur = a[r[k]];
if(new < cur)
{
r[i] = r[k];
l[i] = new;
}
else if(new == cur)
{
r[i] = r[k] + 1;
l[i] = 0;
}
}
if(r[i] == n)
{
cout << "YES";
return 0;
}
}
cout << "NO";
}