Submission #711012

#TimeUsernameProblemLanguageResultExecution timeMemory
711012phoenixBank (IZhO14_bank)C++17
100 / 100
163 ms8624 KiB
#include<bits/stdc++.h> using namespace std; int n, m; int dp[(1 << 20)], w[(1 << 20)], b[20]; int sum_a[30], a[30]; 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]; sum_a[i] = a[i] + sum_a[i - 1]; } for(int i = 0; i < m; i++) cin >> b[i]; for(int msk = 0; msk < (1 << m); msk++) { for(int i = 0; i < m; i++) { if(msk >> i & 1) w[msk] += b[i]; } } for(int msk = 1; msk < (1 << m); msk++) { for(int i = 0; i < m; i++) { if(~msk >> i & 1) continue; int msk1 = msk ^ (1 << i); dp[msk] = max(dp[msk], dp[msk1] + (w[msk1] - sum_a[dp[msk1]] + b[i] == a[dp[msk1] + 1])); } } cout << (dp[(1 << m) - 1] == n ? "YES" : "NO"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...