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;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, m; cin >> n >> m;
int a[n+1], b[m];
a[0] = 0;
for(int i=1; i<=n; ++i){
cin >> a[i]; a[i] += a[i-1];
}
for(int& i : b) cin >> i;
int lim = (1<<m);
int dp[lim]; // dp[i] -> max index(a) to which it's possible to distribute notes in mask
for(int& i : dp) i = 0;
int ok = 0;
for(int i=0; i<lim; ++i){
int sum = 0;
for(int j=0; j<m; ++j){
if(i&(1<<j)) sum += b[j];
}
for(int j=0; j<m; ++j){
if(i&(1<<j)){
if(a[dp[i-(1<<j)]+1]==sum){
dp[i] = max(dp[i], dp[i-(1<<j)]+1);
}
dp[i] = max(dp[i], dp[i-(1<<j)]);
}
}
ok |= dp[i]==n;
}
cout << (ok ? "YES\n" : "NO\n");
}
# | 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... |