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 ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pk pop_back
#define yes cout << "YES\n"
#define no cout << "NO\n"
using namespace std;
ll n, m, k, mod = 1e9 + 7;
map<ll, ll> mp;
string s;
pair <ll, ll> dp[1100005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
srand(time(0));
cin >> n >> m;
vector <ll> a(n + 1);
vector <ll> b(m + 1);
for (ll i = 1; i <= n; ++i) {
cin >> a[i];
}
for (ll i = 1; i <= m; ++i) {
cin >> b[i];
}
for (ll mask = 1; mask < (1 << m); ++mask) {
for (ll cur = 0; cur < m; ++cur) {
if ((mask >> cur) & 1) {
ll pred_mask = mask ^ (1 << cur);
ll total = dp[pred_mask].second + b[cur + 1];
ll done = dp[pred_mask].first;
if (done < n && a[done + 1] == total && dp[mask].first <= done) {
dp[mask] = {done + 1, 0};
} else {
if (dp[mask].first <= done) {
dp[mask] = {done, total};
}
}
}
}
}
if (dp[(1 << m) - 1].first == 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... |