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;
const int N = 20;
bool dp[1<<N];
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
vector<int> a = {0}, b(m);
for(int i = 0; i < n; i++) {
int x; cin >> x;
a.push_back(a.back()+x);
}
for(int i = 0; i < m; i++) cin >> b[i];
dp[0] = 1;
for(int msk = 0; msk < (1<<m); msk++) {
if (!dp[msk]) continue;
int sum = 0;
for(int j = 0; j < m; j++) {
if (msk & (1<<j)) sum += b[j];
}
int idx = 0;
while(idx+1 < (int)size(a) && sum >= a[idx+1]) idx++;
if (idx == int(size(a))-1) {
cout << "YES" << endl;
return 0;
}
for(int j = 0; j < m; j++) {
if (msk & (1<<j)) continue;
if (sum+b[j] <= a[idx+1]) {
dp[msk|(1<<j)] = 1;
}
}
}
cout << "NO" << endl;
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... |