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;
int dp[2000000];
int sb[2000001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin >> n >> m;
vector<int> haha(n);
vector<int> bruh(m);
for(int i = 0; i < n; i++) {
cin >> haha[i];
if(i != 0) {
haha[i]+=haha[i-1];
}
}
for(int i = 0; i < m; i++) {
cin >> bruh[i];
}
for(int i = 0; i < (1 << m); i++) {
sb[i] = 0;
for(int j = 0; j < m; j++) {
if((1 << j)&i) {
sb[i]+=bruh[j];
}
}
}
dp[0] = 0;
bool ans = false;
for(int i = 1; i < (1 << m); i++) {
dp[i] = 0;
for(int j = 0; j < m; j++) {
if((1 << j)&i) {
dp[i] = max(dp[i],dp[i-(1 << j)]);
}
}
if(haha[dp[i]] == sb[i]) {
dp[i]++;
}
if(dp[i] == n) {
ans = true;
break;
}
}
if(ans) {
cout << "YES";
}
else {
cout << "NO";
}
return 0;
}
# | 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... |