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 n, m;
int a[25];
bool solve(int pos, int n1, int b[], int m1, int sum, int cnt){
if(n1-1>m1) return 0;
if(pos==n) return 1;
if(sum==a[pos+1]) return solve(pos+1,n1-1,b,m1-cnt,0,0);
for(int i=1;i<=m;i++){
if(b[i]!=0){
sum+=b[i];
//cout << sum << endl;
if(sum>a[pos]) return 0;
int lol=b[i];
b[i]=0;
if(solve(pos,n1,b,m1,sum,cnt+1)) return 1;
b[i]=lol;
sum-=lol;
}
}
return 0;
}
int main(){
cin >> n >> m;
int b[m+1];
for(int i=1;i<=n;i++){
cin >> a[i];
}
for(int j=1;j<=m;j++){
cin >> b[j];
}
sort(b+1,b+n+1);
if(solve(0,n,b,m,0,0)) cout << "YES";
else cout << "NO";
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... |