# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
858793 | phongcd | Bank (IZhO14_bank) | C++14 | 2 ms | 348 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>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair <int, int>
#define ill pair <ll, ll>
#define ild pair <ld, ld>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define file "test"
using namespace std;
const int N = 22;
const ll MOD = 998244353;
const ll INF = 1e18;
const ll base = 311;
const int BLOCK_SIZE = 400;
int n, m;
int a[N], b[N], f[N][1 << N];
vector <int> h[1002];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
#endif
cin >> n >> m;
int ma = 0;
for (int i = 1; i <= n; i ++)
cin >> a[i], ma = max(ma, a[i]);
for (int i = 0; i < m; i ++) cin >> b[i];
for (int s = 1; s < (1 << m); s ++) {
int sum = 0;
for (int j = 0; (1 << j) <= s; j ++)
if (s >> j & 1) sum += b[j];
if (sum <= ma) h[sum].push_back(s);
}
f[0][0] = 1;
for (int i = 1; i <= n; i ++)
for (int s = 0; s < (1 << m); s ++) {
if (!f[i - 1][s]) continue;
for (int j: h[a[i]])
if ((s & j) == 0) f[i][s | j] = 1;
}
for (int j = 1; j < (1 << m); j ++)
if (f[n][j]) {
cout << "YES";
return 0;
}
cout << "NO";
}
/*
/\_/\ zzZ
(= -_-)
/ >u >u
*/
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... |