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;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
#define fi first
#define se second
#define sz(a) (ll)a.size()
#define all(a) (a).begin(), (a).end()
const ll N = 2e5 + 5;
const ll V = 1e5 + 5;
const ll blocksz = 450;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ld pi = acosl(-1);
ll a[21], b[21], dp[21][1 << 20];
vector<ll> adj[1001];
void doing_job(){
ll n, m; cin >> n >> m;
for (int i = 1; i <= n; ++i){
cin >> a[i];
}
for (int i = 1; i <= m; ++i){
cin >> b[i];
}
for (int mask = 0; mask < (1 << m); ++mask){
ll sum = 0;
for (int i = 0; i < m; ++i){
if (mask >> i & 1){
sum += b[i + 1];
}
}
if (sum <= 1000){
adj[sum].push_back(mask);
}
}
dp[0][0] = 1;
for (int i = 0; i < n; ++i){
for (int mask = 0; mask < (1 << m); ++mask){
if (!dp[i][mask]) continue;
for (ll m : adj[a[i + 1]]){
if (m & mask) continue;
dp[i + 1][mask | m] |= dp[i][mask];
}
}
}
for (int mask = 1; mask < (1 << m); ++mask){
if (dp[n][mask]){
cout << "YES"; return;
}
}
cout << "NO";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll t = 1; // cin >> t;
while (t--){
doing_job();
}
}
# | 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... |