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;
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n + 1), pref(n + 1), b(m);
for(int i = 1; i <= n; ++i)
cin >> a[i], pref[i] = pref[i - 1] + a[i];
for(int &i : b)
cin >> i;
vector<int> dp(1 << 21);
dp[0] = 1;
int ok = 0;
for(int mk = 0; mk < (1 << m); ++mk){
int sum = 0;
for(int i = 0; i < m; ++i)
sum += (mk >> i & 1 ? b[i] : 0);
int id = lower_bound(pref.begin(), pref.end(), sum) - pref.begin();
for(int i = 0; i < m; ++i)
if((mk >> i & 1) and (b[i] <= sum - pref[id - 1]))
dp[mk] |= dp[mk ^ (1 << i)];
ok |= (pref[n] == sum and dp[mk]);
}
cout << (ok ? "YES" : "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... |