Submission #994132

#TimeUsernameProblemLanguageResultExecution timeMemory
994132SharkyBank (IZhO14_bank)C++17
100 / 100
165 ms8640 KiB
// hi amogus // 復健ing #include <bits/stdc++.h> using namespace std; const int N = 20; int dp[1 << N], a[N], b[N], sum[1 << N], ps[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; if (i) ps[i] = ps[i - 1] + a[i]; else ps[i] = a[i]; } for (int i = 0; i < m; i++) cin >> b[i]; for (int i = 0; i < (1 << m); i++) { for (int j = 0; j < m; j++) if (i & (1 << j)) sum[i] += b[j]; } for (int i = 0; i < (1 << m); i++) { for (int j = 0; j < m; j++) { if (!(i & (1 << j))) continue; int k = dp[i ^ (1 << j)]; int s = (!k ? 0 : ps[k - 1]); if (sum[i] - s == a[k]) dp[i] = max(dp[i], k + 1); else dp[i] = max(dp[i], k); } if (dp[i] == n) return cout << "YES\n", 0; } 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...