This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define trav(a, x) for(auto& a : x)
#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define ROF(i, a, b) for (int i=(a); i>=(signed)(b); i--)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define vi vector<int>
typedef long long ll;
const int MAXN = 2e5;
const int mod = 1e9 + 7, MOD = 998244353;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m; cin >> n >> m;
vector<int> a(n), b(m);
F0R(i, n) cin >> a[i]; F0R(i, m) cin >> b[i];
vector<pair<int, int>> dp(1 << m, {-1, 0});
dp[0] = {0, 0};
F0R(i, 1 << m) {
if(dp[i].first == n) {
cout << "YES\n";
exit(0);
}
if(dp[i].first == -1) continue;
F0R(j, m) if(((1 << j) & i) == 0) {
int k = dp[i].first;
int l = dp[i].second;
if(l + b[j] < a[k]) {
dp[(1 << j) | i].second = l + b[j];
dp[(1 << j) | i].first = k;
} else if(l + b[j] == a[k]) {
dp[(1 << j) | i].first = k+1;
dp[(1 << j) | i].second = 0;
}
}
}
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... |