This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name oF the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
using namespace std;
const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 20;
int n, m, a[1000], b[1000];
pii dp[1<<maxn];
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int msk = 0; msk < (1<<m); msk++) dp[msk].F = -1;
dp[0].F = 0;
for (int msk = 0; msk < (1<<m); msk++) {
if (dp[msk].F == -1) continue;
if (dp[msk].F == n) {
cout << "YES\n"; return 0;
}
for (int i = 0; i < m; i++) {
if (msk&(1<<i)) continue;
if (dp[msk].S+b[i] == a[dp[msk].F]) dp[msk+(1<<i)] = mp(dp[msk].F+1, 0);
else if (dp[msk].S+b[i] < a[dp[msk].F]) dp[msk+(1<<i)] = mp(dp[msk].F, dp[msk].S+b[i]);
}
}
cout << "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... |