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;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = (1<<20)+5;
#define all(x) x.begin(), x.end()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int n, m, a[25], b[25], prefix[25], dp[MAXN], sum[MAXN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> a[i], prefix[i] = prefix[i-1] + a[i];
for(int i = 1; i <= m; i++)
cin >> b[i];
for(int mask = 1; mask < (1<<m); mask++) {
for(int j = 0; j < m; j++) {
if(((1<<j) & mask) == 0) continue;
sum[mask] = sum[mask - (1<<j)] + b[j+1];
dp[mask] = max(dp[mask], dp[mask - (1<<j)]);
}
if(sum[mask] == prefix[dp[mask]+1]) dp[mask]++;
}
if(dp[(1<<m) - 1] == n) cout << "YES\n";
else cout << "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... |