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 int long long
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
vector<pair<int, int>> dp(1<<m);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int mask = 0; mask < (1<<n); mask++) {
for (int j = 0; j < mask; j++) {
if(mask >> j & 1) {
int mask2 = mask ^ (1 << j);
int sum = dp[mask2].second;
sum += b[j];
if(sum == a[dp[mask2].first + 1]) dp[mask] = {dp[mask2].first+1, 0};
else if(sum < a[dp[mask2].first+1]) dp[mask] = {dp[mask2].first, sum};
}
}
if(dp[mask].first == n) {cout << "YES\n"; return;}
}
cout << "NO";
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while(t--) {
solve();
}
}
# | 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... |