Submission #1089236

#TimeUsernameProblemLanguageResultExecution timeMemory
1089236vjudge1Bank (IZhO14_bank)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> #define EmirBey ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0); #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define int long long using namespace std; const int N = 220; int n,m,a[N],b[N],used[N]; bool rec(int j){ if(j==n)return 1; int cur=a[j]; function<bool(int,int,int)>dfs = [&](int start , int t , int p)->bool{ if(t==cur){ return rec(j+1); } if(t>cur){ return 0; } for(int i=start ; i<=n ; i++){ if(!used[b[i]] && b[i]+t<=cur){ if(start>i && b[i]==b[i-1] && !used[b[i-1]]){ continue; } used[b[i]]=1; if(dfs(i+1 , t+b[i] , b[i])==1){ return 1; }else{ used[b[i]]=0; } } } return 0; }; return dfs(0,0,-1); } void putin() { cin>>n>>m; int tot=0,bank=0; for(int i=1 ; i<=n ; i++)cin>>a[i],tot+=a[i]; for(int i=1 ; i<=m ; i++)cin>>b[i],bank+=b[i]; sort(a+1 , a+n+1 , greater<int>()); sort(b+1 , b+n+1 , greater<int>()); if(tot>bank)cout<<tot<<' '<<bank<<' '<<"NO\n"; else{ if(!rec(1))cout<<"NO\n"; else cout<<"YES\n"; } } signed main() { EmirBey int tt=1; //cin>>tt; while(tt--){ putin(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...