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;
#define pr pair<int, int>
#define ll long long
#define pb push_back
#define f first
#define s second
int main(){
int n, m; cin>>n>>m;
multiset<int> a;
vector<int> b(m);
//int amax=0;
for (int i=0; i<n; i++) {
int temp; cin>>temp;
}
for (int i=0; i<m; i++) cin>>b[i];
vector<pair<multiset<int>, int>> dp(1<<m, {a, 0});
for (int x=1; x<(1<<m); x++){
pair<multiset<int>, int> mast=dp[x];
multiset<int> nd=mast.f;
for (int i=0; i<m; i++){
if(x&(1<<i)){
pair<multiset<int>, int> prev=dp[x^(1<<i)];
multiset<int> elem=prev.f; int last=prev.s;
last+=b[i];
if(elem.find(last)!=elem.end()){
elem.erase(last); last=0;
}
if(nd.size()>elem.size()){
dp[x]={elem, last};
}
}
}
}
multiset<int> sf=dp[(1<<m)-1].f;
if(sf.size()==0) cout<<"YES";
else cout<<"NO";
}
# | 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... |