제출 #397912

#제출 시각아이디문제언어결과실행 시간메모리
397912Barbod은행 (IZhO14_bank)C++14
100 / 100
96 ms8520 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1 << 21; int n, m, a[30], b[30], p[30], sum; pair <int, int> dp[N]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i], sum -= a[i]; for (int i = 0; i < m; i++) cin >> b[i], sum += b[i]; if (sum < 0) return cout << "NO\n", 0; if (sum > 0) a[n] = sum, n++; p[0] = a[0]; for (int i = 1; i < n; i++) p[i] = p[i - 1] + a[i]; cout << '\n'; for (int mask = 0; mask < (1 << m); mask++) if (dp[mask].first || !mask) { for (int j = 0; j < m; j++) if (!((mask >> j) & 1)) { if (dp[mask].first + b[j] == p[dp[mask].second]) dp[mask ^ (1 << j)] = {dp[mask].first + b[j], dp[mask].second + 1}; else if (dp[mask].first + b[j] < p[dp[mask].second]) dp[mask ^ (1 << j)] = {dp[mask].first + b[j], dp[mask].second}; if (dp[mask ^ (1 << j)].second == n) return cout << "YES\n", 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...