# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
723398 | quochuy147 | Bank (IZhO14_bank) | C++14 | 3 ms | 340 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;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define file "bank"
template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;}
const int mod = 1e9 + 7;
const int N = 20;
int n, m;
int a[N + 5], b[N + 5];
pii f[MASK(N) + 5];
void inp()
{
cin >> n >> m;
for(int i = 1; i <= n; ++i) cin >> a[i];
for(int i = 1; i <= m; ++i) cin >> b[i];
}
void solve()
{
// memset(f, -1, sizeof f);
for(int i = 1; i < MASK(m); ++i) f[i].fi = -1;
f[0] = {1, 0};
for(int i = 1; i < MASK(m); ++i)
for(int j = 1; j <= m; ++j) {
if(MASK(j - 1) & i) {
int pre = MASK(j - 1) ^ i;
if(f[pre].fi == -1) continue;
int cnt = f[pre].fi, val = f[pre].se;
if(val + b[j] < a[cnt]) f[i] = {f[pre].fi, val + b[j]};
if(val + b[j] == a[cnt]) f[i] = {f[pre].fi + 1, 0};
if(f[i].fi > n) {
cout << "YES";
return ;
}
}
}
cout << "NO";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
freopen(file".in" , "r" , stdin);
freopen(file".out" , "w" , stdout);
inp();
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... |