Submission #1119733

#TimeUsernameProblemLanguageResultExecution timeMemory
1119733tsengangBank (IZhO14_bank)C++14
44 / 100
1047 ms508 KiB
#include <bits/stdc++.h> #define ll long long #define ff first #define ss second #define all(x) x.begin(), x.end() #define pb push_back #define ertunt return #define vodka void using namespace std; ll n,m; ll a[21]; ll b[21]; bool yes; bool vis[21]; vodka dfs(ll x){ if(x > n-1){ yes = true; ertunt; } for(ll i = 0; i < m; i++){ if(vis[i] == false){ if(b[i] <= a[x]){ a[x]-=b[i]; vis[i] = true; if(a[x] == 0)dfs(x+1); else dfs(x); vis[i] = false; a[x]+=b[i]; } } } } int main(){ cin >> n >> m; if(n == 1){ ll d; cin >> d; ll b[m+1]; for(ll j = 1; j <= m; j++)cin >> b[j]; for(ll i = 1; i <= (1<<m); i++){ ll res = 0; for(ll j = 0; j < m; j++){ if(i&(1<<j)){ res+=b[j]; } } if(res == d){ cout << "YES"; ertunt 0; } } cout << "NO"; ertunt 0; } for(ll i = 0; i < n; i++) cin >> a[i]; for(ll i = 0; i < m; i++) cin >> b[i]; sort(a,a+n); sort(b,b+m); dfs(0); if(yes)cout << "YES\n"; else cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...