제출 #719829

#제출 시각아이디문제언어결과실행 시간메모리
719829tcmmichaelb139은행 (IZhO14_bank)C++17
0 / 100
3 ms340 KiB
#include "bits/stdc++.h" using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> a(n), b(m); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; vector<int> sum(n, 0); for (int i = 1; i <= n; i++) sum[i] = a[i - 1] + sum[i - 1]; int dp[1 << m]; memset(dp, 0, sizeof dp); for (int i = 0; i < 1 << m; i++) { int cursum = 0; for (int j = 0; j < m; j++) if (i & (1 << j)) cursum += b[i]; cursum -= sum[dp[i]]; for (int j = 0; j < m; j++) if (!(i & (1 << j))) { if (cursum + b[j] < a[dp[i]]) dp[i | (1 << j)] = max(dp[i | (1 << j)], dp[i]); if (cursum + b[j] == a[dp[i]]) dp[i | (1 << j)] = max(dp[i | (1 << j)], dp[i] + 1); } } for (int i = 0; i < 1 << m; i++) if (dp[i] == 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...