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 <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int mod = 1e9 + 7;
int dp[(1<<21)];
int main(){
int n, m; cin >> n >> m;
int mas[n];
int pref[n];
for(int i = 0; i < n; i++){
cin >> mas[i];
}
pref[0] = mas[0];
for(int i = 0; i < n; i++){
pref[i] = pref[i-1] + mas[i];
}
int kup[m];
for(int i = 0; i < m; i++){
cin >> kup[i];
}
for(int i = 0; i < (1 << m); i++){
int sum = 0;
for(int j = 0; j < m; j++){
if((1 << j) & i) {
sum += kup[i];
}
}
for(int j = 0; j < m; j++){
if((1 << j) & i) {
if(sum == pref[dp[i - (1 << j)]])
dp[i] = max(dp[i], dp[i - (1 << j)] + 1);
else dp[i] = max(dp[i], dp[i - (1 << j)]);
}
}
}
if(dp[(1 << m) - 1] == n) cout << "YES" << endl;
else cout << "NO" << endl;
}
# | 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... |