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(){
// freopen("main.in", "r", stdin);
// freopen(".out", "w", stdout);
int n, m; cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
vector<pair<int,int>> dp((1 << m), make_pair(0, -1));
dp[0].second = a[0];
bool works = false;
pair<int, int> p;
for (int i = 1; i < (1<<m); i++){
for (int j = 0; j < m; j++){
if(i & (1 << j)){
p = dp[i ^ (1 << j)];
if(p.second < b[j]) continue;
p.second -= b[j];
if(p.second == 0){
p.first++;
if(p.first == n){
works=true;
dp[i]=p;
break;
}
p.second = a[p.first];
}
if(p.first >= dp[i].first)dp[i] = p;
}
}
}
if(works) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
# | 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... |