Submission #1100900

#TimeUsernameProblemLanguageResultExecution timeMemory
1100900HuyATBank (IZhO14_bank)C++14
100 / 100
105 ms8644 KiB
#include<bits/stdc++.h> #define newl '\n' const int N = 20 + 10; const int V = 1e7 + 10; const long long INF = 1e18; const long long M = 1e9 + 7; std::pair<int,int> f[(1 << 20)]; int n,m,a[N + 1],b[N + 1]; void readData(){ std::cin >> n >> m; assert(std::max(n,m) <= 20); for(int i = 0;i < n;++i){ std::cin >> a[i]; assert(a[i] > 0 && a[i] <= 1000); } for(int i = 0;i < m;++i){ std::cin >> b[i]; assert(b[i] > 0 && b[i] <= 1000); } } bool solve(){ f[0] = {0,-a[0]}; for(int i = 1;i < (1 << m);++i){ f[i].second = -1e9; for(int j = 0;j < m;++j){ if((i >> j) & 1){ int p = (i & (~(1 << j))); if(f[p].second + b[j] < 0){ f[i] = std::max(f[i],{f[p].first,f[p].second + b[j]}); }else if(f[p].second + b[j] == 0){ f[i] = std::max(f[i],{f[p].first + 1,-a[f[p].first + 1]}); } } if(f[i].first == n){ return true; } } } // std::cout << f[17].first << " " << f[17].second << newl; return false; } int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr);std::cout.tie(nullptr); readData(); std::cout << (solve() ? "YES" : "NO"); 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...