Submission #17663

#TimeUsernameProblemLanguageResultExecution timeMemory
17663ZiyaZaBank (IZhO14_bank)C++14
100 / 100
127 ms620 KiB
#include <iostream> #include <algorithm> using namespace std; int n,m,a[25],b[25],i,used[25],ans=0,suma=0,sumb=0; void dfs(int sum, int step, int start) { if (ans==1 || sum>a[step]) return; if (sum==a[step]) { sum=0; step++; start=0; if (step==n) { ans=1; return; } } for (int i=start;i<m;i++) { if (used[i]==0) { used[i]=1; dfs(sum+b[i],step,i); used[i]=0; } } } int main() { cin>>n>>m; for (i=0;i<n;i++) { cin>>a[i]; suma+=a[i]; } for (i=0;i<m;i++) { cin>>b[i]; sumb+=b[i]; } if (suma>sumb) cout<<"NO"<<endl; else { sort(a,a+n); reverse(a,a+n); sort(b,b+m); reverse(b,b+m); dfs(0,0,0); if (ans==1) cout<<"YES"<<endl; else cout<<"NO"<<endl; } 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...