# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1012012 | if_test_AC | Bank (IZhO14_bank) | C++14 | 82 ms | 16980 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.
//author : TCT
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define st first
#define se second
typedef long long ll;
typedef pair<ll, ll> ii;
#define int long long
const int INF = 1e9;
const ll LINF = 1e18;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0 ,0};
const int N = 20;
int n, m;
int a[N + 4], b[N + 4];
ii dp[(1 << N) + 4];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) cin >> b[i];
memset(dp, -1, sizeof dp);
dp[0] = ii(0, 0);
for(int mark = 1; mark < (1 << m); mark++) {
for(int i = 0; i < m; i++) {
if(!(mark & (1 << i))) continue;
ii val = dp[mark ^ (1 << i)];
if(val.st == -1) continue;
if(val.se + b[i] < a[val.st]) dp[mark] = ii(val.st, val.se + b[i]);
else if(val.se + b[i] == a[val.st]) dp[mark] = ii(val.st + 1, 0);
}
if(dp[mark].st == n) {
cout << "YES" << '\n';
return 0;
}
}
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... |