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+1), b(m);
vector<bool> mark(1<<m);
vector<pair<int, int>> dp(1<<m, {0,0});
mark[0] = true;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int mask = 0; mask < (1<<m); mask++) {
for (int j = 0; j < m; j++) {
if(mask >> j & 1) {
int mask2 = mask ^ (1 << j);
if(!mark[mask2]) continue;
int sum = dp[mask2].second;
sum += b[j];
if(sum == a[dp[mask2].first + 1]) dp[mask] = {dp[mask2].first+1, 0}, mark[mask] = true;
else if(sum < a[dp[mask2].first+1]) dp[mask] = {dp[mask2].first, sum}, mark[mask] = true;
}
}
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... |