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;
using ll = long long;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n+1), b(m);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 0; i < m; i++) {
cin >> b[i];
}
vector<array<int, 2>> dp(1 << m);
for(int i = 0; i < 1 << m; i++) {
for(int j = 0; j < m; j++) {
if(i & (1 << j)) {
array<int, 2> last = dp[i ^ (1 << j)];
int nxt = last[0]+1;
if(last[1] + b[j] == a[nxt]) {
last[0] = nxt;
last[1] = 0;
}
else {
last[1] += b[j];
}
dp[i] = max(dp[i], last);
}
}
}
if(dp[(1 << m) - 1][0] == n) 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... |