Submission #944324

#TimeUsernameProblemLanguageResultExecution timeMemory
9443244QT0RBank (IZhO14_bank)C++17
100 / 100
94 ms8656 KiB
#include <bits/stdc++.h> using namespace std; int sal[22]; int sal_pref[22]; int val[22]; pair<int,int> maski[1<<20]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,m; cin >> n >> m; for (int i = 1; i<=n; i++){ cin >> sal[i]; sal_pref[i]=sal_pref[i-1]+sal[i]; } for (int i = 0; i<m; i++)cin >> val[i]; const int zak=1<<m; for (int i = 1; i<zak; i++){ for (int j = 0; j<m; j++){ if (i&(1<<j)){ int bez=i^(1<<j); maski[i].second=maski[bez].second+val[j]; maski[i].first=max(maski[i].first,maski[bez].first); if (maski[i].second-sal_pref[maski[bez].first]==sal[maski[bez].first+1]){ maski[i].first=max(maski[i].first,maski[bez].first+1); } if (maski[i].first==n){ cout << "YES\n"; return 0; } } } } cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...