# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
684629 | CyberCow | Bank (IZhO14_bank) | C++17 | 113 ms | 8544 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 <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <stack>
#include <deque>
#define fi first
#define se second
using namespace std;
using ll = long long;
vector<int> a, b;
void solve()
{
int n, m, i, j, x, y;
cin >> n >> m;
for ( i = 0; i < n; i++)
{
cin >> x;
a.push_back(x);
}
for ( i = 0; i < m; i++)
{
cin >> x;
b.push_back(x);
}
vector<int> dp(1 << m, -1);
vector<int> mnac(1 << m, -1);
dp[0] = 0;
mnac[0] = 0;
for (int mask = 0; mask < (1 << m); mask++)
{
for ( j = 0; j < m; j++)
{
if (((1 << j) & mask) == 0)
continue;
int ent = mask ^ (1 << j);
if (dp[ent] == -1)
continue;
int unem = mnac[ent] + b[j];
if (unem == a[dp[ent]])
{
dp[mask] = dp[ent] + 1;
mnac[mask] = 0;
}
else if(unem < a[dp[ent]] && dp[mask] <= dp[ent])
{
dp[mask] = dp[ent];
mnac[mask] = unem;
}
}
if (dp[mask] == n)
{
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--)
{
solve();
}
return 0;
}
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... |