제출 #584392

#제출 시각아이디문제언어결과실행 시간메모리
584392stevancv은행 (IZhO14_bank)C++14
100 / 100
167 ms8656 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 1e5 + 2; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> a(n), b(m); for (int i = 0; i < n; i++) { cin >> a[i]; if (i > 0) a[i] += a[i - 1]; } for (int i = 0; i < m; i++) { cin >> b[i]; } int M = (1 << m); vector<int> sum(M); for (int i = 0; i < M; i++) { for (int j = 0; j < m; j++) { if ((1 << j) & i) sum[i] += b[j]; } } vector<int> dp(M, -1e9); dp[0] = 0; for (int i = 1; i < M; i++) { for (int j = 0; j < m; j++) { if ((1 << j) & i) smax(dp[i], dp[i ^ (1 << j)]); } for (int j = 0; j < n; j++) if (a[j] == sum[i]) dp[i]++; } for (int i = 0; i < M; i++) { if (dp[i] == n) { cout << "YES" << '\n'; return 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...