# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1109965 | DON_F | Bank (IZhO14_bank) | C++14 | 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;
using i64 = long long;
#define all(x) x.begin(), x.end()
#define L(i, b, e) for (int i = b; i < e; ++i)
#define R(i, b, e) for (int i = b; i >= e; --i)
#define pb emplace_back
#define vi vector<int>
#define sz(x) ((int) x.size())
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vi a(n), b(m);
L(i, 0, n)cin >> a[i];
L(i, 0, m)cin >> b[i];
vector<pair<int, int>> dp(1 << m, {-1, -1});
dp[0] = {0, 0};
L(i, 0, 1 << m){
L(j, 0, m){
if ((1 << j) & i || dp[i].first == -1)continue;
if (dp[i].second < n && dp[i].first + b[j] <= a[dp[i].second]){
dp[i + (1 << j)] = {(dp[i].first + b[j] == a[dp[i].second] ? 0 : dp[i].first + b[j]), (dp[i].first + b[j] == a[dp[i].second] ? dp[i].second + 1 : dp[i].second)};
}
}
}
int ans = 0;
L(i, 0, 1 << m)if (dp[i].second == n)ans = 1;2 6
cout << (ans ? "YES\n" : "NO\n");
}