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>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 20;
bool dp[2][1<<N];
int a[N], b[N];
int sum[1<<N];
int n, m;
#pragma GCC optimize("O3,unroll-loops")
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> m;
int kooft = 0;
Loop (i,0,n) {
cin >> a[i];
kooft -= a[i];
}
Loop (i,0,m) {
cin >> b[i];
kooft += b[i];
}
if (kooft < 0) {
cout << "NO" << '\n';
return 0;
}
memset(dp[0], 1, sizeof(dp[0]));
Loop (i,1,1<<m)
sum[i] = sum[i ^ (i & -i)] + b[__builtin_ctz(i)];
Loop (i,0,n) {
memset(dp[!(i&1)], 0, sizeof(dp[0]));
Loop (j,1,1<<m) {
if (sum[j] == a[i]) {
int sup = 0;
int k = 1 << __builtin_popcount(((1<<m)-1) ^ j);
if (i&1) {
Loop (_,0,k) {
dp[0][sup ^ j] |= dp[1][sup];
sup = ((sup | j) + 1) & (~j);
}
} else {
Loop (_,0,k) {
dp[1][sup ^ j] |= dp[0][sup];
sup = ((sup | j) + 1) & (~j);
}
}
}
}
if (!dp[!(i&1)][(1<<m)-1]) {
cout << "NO\n";
return 0;
}
}
cout << "YES\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... |