Submission #1027642

#TimeUsernameProblemLanguageResultExecution timeMemory
1027642vjudge1Bank (IZhO14_bank)C++14
0 / 100
1075 ms416 KiB
#include <bits/stdc++.h> using namespace std; int n,m; const int MAX=20; int plata[MAX],pari[MAX]; bool flag=false; void f(int i,int cnt[]) { if(i>=m) { for(int j=0; j<n; j++)if(plata[j]!=cnt[j])return; flag=true; return; } for(int j=0; j<n; j++) { if(cnt[j]+pari[i]>plata[j])continue; //cout<<"add: "<<pari[i]<<" on pos: "<<j+1<<endl; cnt[j]+=pari[i]; f(i+1,cnt); cnt[j]-=pari[i]; f(i+1,cnt); } } int main() { cin>>n>>m; for(int i=0; i<n; i++)cin>>plata[i]; sort(plata,plata+n); for(int i=0; i<m; i++)cin>>pari[i]; int cnt[n]; memset(cnt,0,sizeof(cnt)); f(0,cnt); if(flag)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...