Submission #170056

#TimeUsernameProblemLanguageResultExecution timeMemory
170056itglBank (IZhO14_bank)C++14
0 / 100
2 ms376 KiB
#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+1]) 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(a+1,a+n+1); sort(b+1,b+n+1); if(solve(0,n,b,m,0,0)) cout << "YES"; else cout << "NO"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...