이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define fi first
#define si second
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
int ar[21], br[21];
int dp[(1 << 21) + 1];
int sum[(1 << 21) + 1];
int ans;
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> ar[i], ar[i] += ar[i - 1];
for (int i = 1; i <= m; ++i) cin >> br[i];
for (int i = 1; i <= (1 << (m + 1)) - 1; ++i) {
int s = 0;
for (int j = 1; j <= m; ++j) {
if (i & (1 << j)) s += br[j];
}
sum[i] = s;
}
memset(dp, -1, sizeof dp);
dp[0] = 0;
for (int now = 1; now <= (1 << (m + 1)) - 1; ++now) {
for (int i = 1; i <= m; ++i) {
if (!(now & (1 << i))) continue;
int from = now ^ (1 << i);
if (dp[from] == -1) continue;
if (sum[now] == ar[dp[from] + 1]) {
dp[now] = max(dp[now], dp[from] + 1);
} else if (sum[now] < ar[dp[from] + 1]) {
dp[now] = max(dp[now], dp[from]);
}
ans = max(ans, dp[now]);
}
}
cout << (ans >= n ? "YES" : "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... |