Submission #100494

#TimeUsernameProblemLanguageResultExecution timeMemory
1004941KhanBank (IZhO14_bank)C++14
71 / 100
10 ms412 KiB
/// 1n the name of GOD #include <bits/stdc++.h> using namespace std; #define ko exit(0); #define nl '\n' #define ios ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0); #define sz(s) (int)s.size() #define all(s) s.begin(), s.end() #define oll(s, n, c) (s) + (c), s + (n) + c #define pb push_back #define ff first #define ss second #define pii pair<int, int> typedef long long ll; typedef double db; const int N = 1e5 + 111; const int M = 1e9 + 7; int q, n, a[N], b[N]; void solve(int id){ if(id > n){ int w = 0; for(int i = 1; i <= q; ++i){ if(b[i]){ w++; return; } } if(!w){ cout << "YES"; exit(0); } return; } for(int i = 1; i <= q; ++i){ if(b[i] >= a[id]){ b[i] -= a[id]; solve(id + 1); b[i] += a[id]; } } solve(id + 1); } int can[N]; int main(){ cin >> q >> n; for(int i = 1; i <= q; ++i){ cin >> b[i]; } for(int i = 1; i <= n; ++i){ cin >> a[i]; } if(max(q, n) <= 10){ solve(1); cout << "NO"; return 0; } can[0] = 1; for(int i = 1; i <= n; ++i){ for(int j = 1111; j >= 0; --j){ if(can[j]){ can[j + a[i]] = 1; } } } for(int i = 1; i <= q; ++i){ if(!can[b[i]]){ cout << "NO"; return 0; } } cout << "YES"; 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...