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 pb push_back
#define pp pop_back
#define mp make_pair
#define bb back
#define ff first
#define ss second
#define int long long
using namespace std;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("bank.in", "r", stdin);
// freopen("bank.out", "w", stdout);
int n, m;
cin >> n >> m;
vector<int> people(n), money(m);
for (int i = 0; i < n; i++)
cin >> people[i];
for (int i = 0; i < m; i++)
cin >> money[i];
vector<vector<int> > make(1005), dp(n+1);
for (int b = 0; b < (1<<m); b++) {
int now = 0;
for (int j = 0; j < m; j++)
if (b&(1<<j)) now += money[j];
if (now <= 1000)
make[now].pb(b);
}
dp[0].pb(0);
for (int i = 0; i < n; i++) {
for (int state : dp[i]) {
for (int b : make[people[i]]) {
if ((b^state) < (b+state)) continue;
dp[i+1].pb(b^state);
}
}
}
if (dp[n].empty())
cout << "NO\n";
else
cout << "YES\n";
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
# | 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... |