Submission #548918

#TimeUsernameProblemLanguageResultExecution timeMemory
548918HanksburgerBank (IZhO14_bank)C++17
100 / 100
160 ms2416 KiB
#include <bits/stdc++.h> using namespace std; bool visited[1048580], dp[1048580]; int a[25], b[25], n, m; bool f(int x) { if (visited[x]) return dp[x]; visited[x]=1; int index=0, sum=0; for (int i=1; i<=m; i++) if (x&(1<<(i-1))) sum+=b[i]; for (int i=1; i<=n; i++) { if (sum<a[i]) { index=i; break; } sum-=a[i]; } if (!index) { dp[x]=1; return 1; } bool res=0; for (int i=1; i<=m; i++) if (!(x&(1<<(i-1))) && b[i]<=a[index]-sum) res|=f(x|(1<<(i-1))); dp[x]=res; return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i=1; i<=n; i++) cin >> a[i]; for (int i=1; i<=m; i++) cin >> b[i]; cout << (f(0)?"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...