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;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 25;
int n, m, a[MXN], c[MXN];
int p[MXN];
bitset<1050000> dp;
int sum_of(int *a, int *b) {
int ans = 0;
while (a != b) {
ans += *a;
a++;
}
return ans;
}
int sum(int I) {
int ans = 0;
FOR(i, 0, m) if (I & (1 << i)) {
ans += c[i];
}
return ans;
}
int cv(int I) {
return upper_bound(p, p + n, sum(I)) - p - 1;
}
bool DP(int I) {
FOR(i, 0, m) if (I & (1 << i)) {
int I_ = I ^ (1 << i);
if (!dp[I_]) continue;
int x = cv(I_), y = cv(I);
if (x + 1 < y) continue;
if (x == y) return true;
if (p[y] == sum(I)) return true;
}
return false;
}
bool miku() {
cin >> n >> m;
FOR(i, 0, n) cin >> a[i];
FOR(i, 0, m) cin >> c[i];
if (sum_of(a, a + n) > sum_of(c, c + m)) return false;
FOR(i, 0, n) p[i + 1] = p[i] + a[i];
if (sum_of(a, a + n) != sum_of(c, c + m)) {
p[n + 1] = sum_of(c, c + m);
n = n + 2;
} else {
n = n + 1;
}
dp[0] = true;
FOR(I, 1, (1 << m)) dp[I] = DP(I);
// FOR(i, 0, (1 << m)) cout << dp[i] << ' ';
// cout << endl;
return dp[(1 << m) - 1];
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
cout << (miku() ? "YES" : "NO") << '\n';
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... |