Submission #545560

#TimeUsernameProblemLanguageResultExecution timeMemory
545560stark2002Bank (IZhO14_bank)C++17
100 / 100
123 ms8652 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1005; int main() { cin.tie(NULL)->sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> v(n), a(m); for(auto& i: v) cin >> i; for(auto& i: a) cin >> i; vector<int> p(1<<m, -1), l(1<<m, -1); p[0] = l[0] = 0; for(int i = 1; i < (1<<m); i++) { for(int j = 0; j < m; j++) { if((i>>j)&1) { if(p[i^(1<<j)]==-1) continue; int x = i^(1<<j), num = p[x]; if(l[x]+a[j]==v[num]) { p[i] = p[x] + 1; l[i] = 0; break; } else if(l[x]+a[j] < v[num]) { p[i] = p[x]; l[i] = l[x]+a[j]; } } } if(p[i]==n) { cout << "YES\n"; break; } else if(i==(1<<m)-1) { cout << "NO\n"; } } 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...