제출 #1000575

#제출 시각아이디문제언어결과실행 시간메모리
1000575niwrad은행 (IZhO14_bank)C++17
100 / 100
179 ms4700 KiB
#include <bits/stdc++.h> using namespace std; int main() { //freopen("guard.in", "r", stdin); //freopen("guard.out", "w", stdout); int n, m; cin >> n >> m; vector<int> a(n); vector<int> b(m); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } vector<int> dp((1 << m)); dp[0] = 1; for (int i = 0; i < (1 << m); i++) { if (dp[i] == 1) { int sum = 0; for (int j = 0; j < m; j++) { if (i & (1 << j)) { sum += b[j]; } } int ind = 0; while (ind < n && sum >= a[ind]) { sum -= a[ind]; ind++; } if (ind == n) { continue; } int r = a[ind] - sum; for (int j = 0; j < m; j++) { if (!(i & (1 << j)) && r >= b[j]) { dp[i | (1 << j)] = 1; } } } } int a_s = 0; for (int i = 0; i < n; i++) { a_s += a[i]; } bool con = false; for (int i = 0; i < (1 << m); i++) { if (dp[i] == 1) { int sum = 0; for (int j = 0; j < m; j++) { if (i & (1 << j)) { sum += b[j]; } } if (a_s == sum) { con = true; } } } if (con) { cout << "YES\n"; } else { 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...